for cycle php code example
Example 1: 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 2: loop through php array
foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement
Example 3: php loop through array
foreach($array as $item=>$values){
echo $values->filepath;
}