foreach array print php code example
Example 1: php loop through array
$clothes = array("hat","shoe","shirt");
foreach ($clothes as $item) {
echo $item;
}
Example 2: loop through values of hash php
foreach ($array as $key => $val) {
print "$key = $val\n";
}
Example 3: php foreach
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $val) {
echo "$x = $val<br>";
}
?>
Example 4: php ofreach
<?php
$a = array(1, 2, 3, 17);
foreach ($a as $index => $v) {
echo "Current value of \$a: $v.\n";
}
?>