PHP 2D Array Iteration Guide
In PHP, you can use nested foreach loops to iterate through a two-dimensional array and output its elements. Here is a simple example:
$twoDimArray = array(
array("A", "B", "C"),
array("D", "E", "F"),
array("G", "H", "I")
);
foreach ($twoDimArray as $row) {
foreach ($row as $element) {
echo $element . " ";
}
echo "<br>";
}
In the above example, $twoDimArray is a two-dimensional array containing 3 subarrays. The first foreach loop iterates through each subarray (each row), while the second foreach loop iterates through each element in each subarray (each element), and outputs it to the screen. The final output will be:
A B C
D E F
G H I