for statement 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: foreach loop array php
foreach (array as $value){
//code to be executed;
print("value : $value");
}
foreach (array as $key => $value){
//code to be executed;
print("key[$key] => $value");
}
Example 3: for loop in php
/*
For loop in php
*/
<?php
for ($i = 0; $i < 10; $i++) {
echo $i."<br>";
}
?>