1$clothes = array("hat","shoe","shirt");
2foreach ($clothes as $item) {
3 echo $item;
4}
1$arr = array(1, 2, 3, 4);
2foreach ($arr as &$value) {
3 $value = $value * 2;
4}
1for ($i = 0; $i < count($array); $i++) {
2 echo $array[$i]['filename'];
3 echo $array[$i]['filepath'];
4}
1$arr = ['Item 1', 'Item 2', 'Item 3'];
2
3foreach ($arr as $item) {
4 var_dump($item);
5}
1foreach($array as $i => $item) {
2 echo $item[$i]['filename'];
3 echo $item[$i]['filepath'];
4
5 // $array[$i] is same as $item
6}
1<?php
2$arr = array(1, 2, 3, 4);
3foreach ($arr as &$value) {
4 $value = $value * 2;
5}
6// $arr is now array(2, 4, 6, 8)
7unset($value); // break the reference with the last element
8?>