PHP Multidimensional Array Loop Guide
In PHP, you can use a foreach loop to iterate through a multidimensional array and output its values. Here is an example code:
$multiArray = array(
"fruit" => array("apple", "banana", "orange"),
"vegetable" => array("carrot", "broccoli", "spinach")
);
foreach ($multiArray as $key => $value) {
echo $key . ": ";
foreach ($value as $item) {
echo $item . " ";
}
echo "<br>";
}
In the example above, $multiArray is a multi-dimensional array containing two key-value pairs. The outer foreach loop is used to iterate through each key-value pair in the array, while the inner foreach loop is used to iterate through the value array corresponding to each key, and output the values. This way, you can loop through and output all the values in the multi-dimensional array.