Home Tutorial Php Phparray PHP array length for, PHP array length for loop

 
 

Share on Google+Share on Google+
PHP array length for, PHP array length for loop
Posted on: August 31, 2009 at 12:00 AM
Advertisement
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

 

Advertisement

Related Tags for PHP array length for, PHP array length for loop:


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.

Posted on: August 31, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com