how to iterate through associative array in php 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: how to iterate through php array
$ar = ['Rudi', 'Morie', 'Halo', 'Miki'];
for ($i=0, $len=count($ar); $i<$len; $i++) {
echo "$ar[$i] \n";
}
/*
Rudi
Morie
Halo
Miki
*/