Answers for "loop php"

PHP
10

for loop php

<?php
	$fruits = ["apple", "banana", "orange"];
	for($i=0;$i<count($fruits);$i++){
    echo "Index of ".$i."= ".$fruits[$i]."<br>";
    }
  ?>
Posted by: Guest on December-28-2019
6

for loop in php

/*
For loop in php
*/

<?php
for ($i = 0; $i < 10; $i++) {
     echo $i."<br>";
} 
?>
Posted by: Guest on May-06-2020
4

php for loop

for($i = 0; $i <=10; $i++){
	echo "The index is $i";
}
Posted by: Guest on July-23-2020
3

php loops

#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' => '[email protected]',
        'Jose' => '[email protected]','William' => '[email protected]');
    
     foreach($people as $person => $email){
        echo $person.': '.$email;
        echo '<br>';
}
?>
Posted by: Guest on May-13-2020
1

php loop statement

do
{
    code to be executed
}
while (condition)
Posted by: Guest on May-31-2020
0

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" );
?>
Posted by: Guest on February-24-2020

Browse Popular Code Answers by Language