Share on Google+Share on Google+

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.

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.


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


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

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


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:



while( $counter< $count){

echo ("<br>".$loans[$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




Posted on: August 31, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.