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
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
for ($i = 1; ; $i++) {
if ($i > 10) {
break;
}
echo $i;
}
$i = 1;
for (; ; ) {
if ($i > 10) {
break;
}
echo $i;
$i++;
}
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>";
}
$i = 0;
foreach ($fruits as $value) {
echo "Index of ".$i."= ".$value."<br>";
$i++;
}
?>