Lee
0
Q:

for loop in php

for ($x = 0; $x <= 10; $x++) {
    echo "The number is: $x <br>";
}
10

<?php 
for ($x = 0; $x <= 10; $x++)
{

   echo "The number is: $x <br>";
} 
?>  
13
<?php
	$fruits = ["apple", "banana", "orange"];
	for($i=0;$i<count($fruits);$i++){
    echo "Index of ".$i."= ".$fruits[$i]."<br>";
    }
  ?>
10
for ($x = 0; $x <= 10; $x++) {
     echo "The number is: $x <br>";
} 
10
/*
For loop in php
*/

<?php
for ($i = 0; $i < 10; $i++) {
     echo $i."<br>";
} 
?>
5
for($i = 0; $i <=10; $i++){
	echo "The index is $i";
}
2

for (init counter; test counter; increment counter)
{

  code to be executed 
  for each iteration;

}
2
while (condition) {
   code to be executed;
}
//Example
<?php
   $i = 0;
   $num = 50;
   
   while( $i < 10) {
      $num--;
      $i++;
   }
   
   echo ("Loop stopped at i = $i and num = $num" );
?>
//...................................
foreach (array as value) {
   code to be executed;
}
//Example
<?php
  $array = array( 1, 2, 3, 4, 5);
  
  foreach( $array as $value ) {
     echo "Value is $value <br />";
  	}
?>
3
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" );
?>
0
do
{
    code to be executed
}
while (condition)
0

New to Communities?

Join the community