foreach associative array code example
Example 1: php foreach associative array
$arr = array(
'key1' => 'val1',
'key2' => 'val2',
'key3' => 'val3'
);
foreach ($arr as $key => $val) {
echo "$key => $val" . PHP_EOL;
}
Example 2: loop through values of hash php
<?php
while (list($var, $val) = each($array)) {
print "$var is $val\n";
}
?>