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

When iterating through and manipulating multidimensional arrays in PHP, it is important to use nested loops to access each level of the array. Additionally, using functions like foreach can simplify the process of iterating through arrays. It is also crucial to keep track of the current key and value in the array to perform the necessary manipulations.

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

foreach ($multiArray as $key1 => $innerArray) {
    foreach ($innerArray as $key2 => $value) {
        // Manipulate the value (e.g. add 1 to each element)
        $multiArray[$key1][$key2] = $value + 1;
    }
}

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