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<?php
2$arr = ['Item 1', 'Item 2', 'Item 3'];
3
4foreach ($arr as $item) {
5 var_dump($item);
6}
7
8$dict = array("key1"=>"35", "key2"=>"37", "key3"=>"43");
9
10foreach($dict as $key => $val) {
11 echo "$key = $val<br>";
12}
13?>
1foreach (array as $value){
2 //code to be executed;
3 print("value : $value");
4}
5
6foreach (array as $key => $value){
7 //code to be executed;
8 print("key[$key] => $value");
9}
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
2 <?php
3$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
4
5
6foreach($age as $x => $val) {
7 echo "$x = $val<br>";
8}
9?>
10