php loops
snippet in php

for loop php

user947

<?php
	$fruits = ["apple", "banana", "orange"];
	for($i=0;$i<count($fruits);$i++){
    echo "Index of ".$i."= ".$fruits[$i]."<br>";
    }
  ?>

loop php

user135

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

for loop in php

user6463

/*
For loop in php
*/

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

php loops

user1772

#Loops

<?php
    #loops execute code a set number of times
    /*
    Types of loops
    1-For
    2-While
    3-Do..while
    4 Foreach
    */

    # For Loop usually use if you know the number of times it has to execute
    # @params -it takes an init, condition, increment
    #for($i =0;$i<=11;$i++){
    #echo 'Number: '.$i;
    #echo '<br>';
    #}
    #While loop
    # @ prams - condition
    #$i = 0;
    #while($i < 10){
    #    echo $i;
    #    echo '<br>';
    #    $i++;
    #}
    # Do...while loops
    #@prapms - condition
    /*$i = 0;
    do{
        echo $i;
        echo '<br>';
        $i++;
        }
        while($i < 10);*/
    # Foreach  --- is for arrays
    
    # $people = array('Brad', 'Jose', 'William');
    #     foreach($people as $person){
    #     echo $person;
    #     echo '<br>';
    # }
    $people = array('Tony' => 'tony@example.com',
        'Jose' => 'jose@example.com','William' => 'William@example.com');
    
     foreach($people as $person => $email){
        echo $person.': '.$email;
        echo '<br>';
}
?>

how create loop php

user5679

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 />";
  	}
?>

php loops

user8104

#Loops

<?php
    #loops execute code a set number of times
    /*
    Types of loops
    1-For
    2-While
    3-Do..while
    4 Foreach
    */

    # For Loop usually use if you know the number of times it has to execute
    # @params -it takes an init, condition, increment
    #for($i =0;$i<=11;$i++){
    #echo 'Number: '.$i;
    #echo '<br>';
    #}
    #While loop
    # @ prams - condition
    #$i = 0;
    #while($i < 10){
    #    echo $i;
    #    echo '<br>';
    #    $i++;
    #}
    # Do...while loops
    #@prapms - condition
    /*$i = 0;
    do{
        echo $i;
        echo '<br>';
        $i++;
        }
        while($i < 10);*/
    # Foreach  --- is for arrays
    
    # $people = array('Brad', 'Jose', 'William');
    #     foreach($people as $person){
    #     echo $person;
    #     echo '<br>';
    # }
    $people = array('Tony' => 'tony@example.com',
        'Jose' => 'jose@example.com','William' => 'William@example.com');
    
     foreach($people as $person => $email){
        echo $person.': '.$email;
        echo '<br>';
}
?>