foreach phph code example
Example 1: php foreach
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
Example 2: for each php
<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
foreach ($arr as $key => $value) {
echo "{$key} => {$value} ";
print_r($arr);
}
?>
Example 3: php loop through array
foreach($array as $item=>$values){
echo $values->filepath;
}
Example 4: php loop through array
foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement