while php array loop code example
Example 1: php while loop array
$foodArray = ["Eggs", "Bacon", "HashBrowns", "Beans", "Bread"];
foreach ($foodArray as $food) {
echo $food ."<br />";
}
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 />';
};