for in php code example
Example 1: php loop through array
$clothes = array("hat","shoe","shirt");
foreach ($clothes as $item) {
echo $item;
}
Example 2: for loop php
<?php
$fruits = ["apple", "banana", "orange"];
for($i=0;$i<count($fruits);$i++){
echo "Index of ".$i."= ".$fruits[$i]."<br>";
}
?>
Example 3: 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 4: php for schleife
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
Example 5: foreach loop array php
foreach (array as $value){
print("value : $value");
}
foreach (array as $key => $value){
print("key[$key] => $value");
}
Example 6: for loop in php
/*
For loop in php
*/
<?php
for ($i = 0; $i < 10; $i++) {
echo $i."<br>";
}
?>