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$arr = array(1, 2, 3);
2foreach ($arr as $key => $value) {
3 echo "{$key} => {$value} ";
4}
1<?php
2$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
3
4foreach($age as $x => $val) {
5 echo "$x = $val<br>";
6}
7?>
1$arr = array(
2 'key1' => 'val',
3 'key2' => 'another',
4 'another' => 'more stuff'
5);
6foreach ($arr as $key => $val){
7 //do stuff
8}
9
10//or alt syntax
11foreach ($arr as $key => $val) :
12 //do stuff here as well
13endforeach;
14