php loop 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: how to loop with while in php for array associative
$assocarray = array('a' => 1, 'b' => 2, 'c' => 3);
$keys = array_keys($assocarray);
rsort($keys);
while (!empty($keys)) {
$key = array_pop($keys);
echo $key . ' = ' . $assocarray[$key] . '<br />';
};