PHP foreach
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
garzj
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $val) {
echo "$x = $val<br>";
}
?>
$myArray = [1,2,3];
foreach ($myArray as $item) {
echo $item;
}
$myAssocArray = [1=>'One',2=>'Two',3=>'Three'];
foreach ($myAssocArray as $key => $value) {
echo $key . ' is ' . $value;
}
<?php echo forecah()?>
<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>
foreach ($arr as $value) {
$value = $value * 2;
}
foreach ($arr as &$value) {
echo($value);
}