do while php 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: while loop php

<?php
	$a = 0;
	while($a<=5){
    	echo $a."<br>";
      $a++;
    }
  ?>

Example 3: php for loop

for($i = 0; $i <=10; $i++){
	echo "The index is $i";
}

Example 4: do while php

<?php
$i = 0;
do {
    echo $i;
} while ($i > 0);
?>

Example 5: while true php

while(true) {
 // Infinite Loop
}

Example 6: while in php

<?php
  echo 'nice';
?>

Tags:

Php Example