What are the best practices for handling multi-dimensional arrays in PHP functions?

When working with multi-dimensional arrays in PHP functions, it's important to properly iterate through the nested arrays to access and manipulate the data. One common approach is to use nested loops or recursive functions to traverse the multi-dimensional array and perform the necessary operations.

// Example of handling multi-dimensional arrays in PHP functions

// Function to recursively iterate through a multi-dimensional array
function processMultiArray($array) {
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            processMultiArray($value); // Recursive call for nested arrays
        } else {
            // Perform operations on the individual elements
            echo $value . " ";
        }
    }
}

// Example multi-dimensional array
$multiArray = array(
    'first' => array(1, 2, 3),
    'second' => array(4, 5, 6),
    'third' => array(7, 8, 9)
);

// Call the function to process the multi-dimensional array
processMultiArray($multiArray);