How to Loop Through PHP 2D Arrays?
In PHP, you can use nested foreach loops to iterate through the data in a two-dimensional array. Here is a simple example:
$twoDimensionalArray = array(
array('Alice', 25),
array('Bob', 30),
array('Charlie', 35)
);
foreach ($twoDimensionalArray as $innerArray) {
foreach ($innerArray as $value) {
echo $value . " ";
}
echo "<br>";
}
In the example above, $twoDimensionalArray is a two-dimensional array containing three internal arrays. The outer foreach loop iterates through each internal array in the outer array, while the inner foreach loop iterates through the values in each internal array and outputs them.