What are some alternative methods to modify inner arrays in a multidimensional array in PHP?
When working with multidimensional arrays in PHP, modifying inner arrays can be achieved using various methods such as array_map(), array_walk(), or simply iterating through the array using foreach loop. These functions allow you to apply a callback function to each element of the inner arrays and make modifications as needed.
// Example of using array_map() to modify inner arrays in a multidimensional array
$multiDimArray = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
$modifiedArray = array_map(function($innerArray) {
return array_map(function($value) {
return $value * 2; // Multiply each value by 2
}, $innerArray);
}, $multiDimArray);
print_r($modifiedArray);