for php code example

Example 1: for php

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

Example 2: php for

<?php
/* example 1 */

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}

/* example 2 */

for ($i = 1; ; $i++) {
    if ($i > 10) {
        break;
    }
    echo $i;
}

/* example 3 */

$i = 1;
for (; ; ) {
    if ($i > 10) {
        break;
    }
    echo $i;
    $i++;
}

/* example 4 */

for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
?>

Example 3: php for schleife

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}

Example 4: for loop in php

/*
For loop in php
*/

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

Example 5: php for loop

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

Example 6: for php

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

Tags:

Php Example