1$clothes = array("hat","shoe","shirt");
2foreach ($clothes as $item) {
3 echo $item;
4}
1$arr = ['Item 1', 'Item 2', 'Item 3'];
2
3foreach ($arr as $item) {
4 var_dump($item);
5}
1$ar = ['Rudi', 'Morie', 'Halo', 'Miki'];
2
3for ($i=0, $len=count($ar); $i<$len; $i++) {
4 echo "$ar[$i] \n";
5}
6/*
7Rudi
8Morie
9Halo
10Miki
11*/
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?>
1<?php
2// Declare an array
3$arr = array("green", "blue", "pink", "white");
4
5// Loop through the array elements
6foreach ($arr as $element) {
7 echo "$element ";
8}
9?>
1foreach (array_expression as $value)
2 statement
3foreach (array_expression as $key => $value)
4 statement