What are the best practices for iterating through and modifying multidimensional arrays in PHP?

When iterating through and modifying multidimensional arrays in PHP, it is important to use nested loops to access each level of the array. You can use foreach loops to iterate through the arrays and make modifications as needed. Be cautious when modifying the array within the loop to avoid unexpected behavior.

// Example of iterating through and modifying a multidimensional array
$multiArray = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];

foreach ($multiArray as $key => $subArray) {
    foreach ($subArray as $subKey => $value) {
        $multiArray[$key][$subKey] = $value * 2; // Modify the value in each sub-array
    }
}

print_r($multiArray); // Output the modified multidimensional array