PHP array length for, PHP array length for loop


 

PHP array length for, PHP array length for loop

PHP array length for loop, Get the length of PHP Array and then iterate using for loop.

PHP array length for loop, Get the length of PHP Array and then iterate using for loop.

In this tutorial we will iterate PHP array using the for loop. We will find the length of the array and then print all the values in it.

The following PHP code shows how you can get the array length and then use the for loop to display all the data into the array.

<?php

$loans = array("Home Loan", "Cash Loan", "FHA Loans", "Personal Loans", "Business Loans");

$count=sizeof($loans);

echo ("Total loan types:".$count);

//Now use the for loop to display all the Loan types on browser

for($counter=0;$counter<$count;$counter++){

echo ("<br>".$loans[$counter]);

}

?>

You can also use the while loop to iterate the data of PHP array. In the following code we have achieve the same:

<?php

$counter=0;

while( $counter< $count){

echo ("<br>".$loans[$counter]);

$counter++;

}

?>

Both the code mentioned above will print the following values:

Total loan types: 5
Home Loan
Cash Loan
FHA Loans
Personal Loans
Business Loans

 

0

Ads