for php loop code example
Example 1: for loop php
<?php
$fruits = ["apple", "banana", "orange"];
for($i=0;$i<count($fruits);$i++){
echo "Index of ".$i."= ".$fruits[$i]."<br>";
}
?>
Example 2: for loop in php
/*
For loop in php
*/
<?php
for ($i = 0; $i < 10; $i++) {
echo $i."<br>";
}
?>
Example 3: php loops
#Loops
<?php
$people = array('Tony' => '[email protected]',
'Jose' => '[email protected]','William' => '[email protected]');
foreach($people as $person => $email){
echo $person.': '.$email;
echo '<br>';
}
?>
Example 4: for i php
<?php
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
Example 5: how create loop php
for (initialization; condition; increment){
code to be executed;
}
//Example
<?php
$a = 0;
$b = 0;
for( $i = 0; $i<5; $i++ )
{
$a += 10;
$b += 5;
}
echo ("At the end of the loop a = $a and b = $b" );
?>
//.......................................//
do {
code to be executed;
}
while (condition);
//Example
<?php
$i = 0;
$num = 0;
do {
$i++;
}
while( $i < 10 );
echo ("Loop stopped at i = $i" );
?>
Example 6: php loop statement
do
{
code to be executed
}
while (condition)