How can recursion be effectively utilized to navigate and manipulate multi-dimensional arrays in PHP, especially in cases where the structure is complex or nested?

When dealing with complex or nested multi-dimensional arrays in PHP, recursion can be effectively utilized to navigate and manipulate the data. Recursion allows for a function to call itself within the function, which is useful for traversing through nested arrays of unknown depth. By using recursion, you can easily access and modify elements within multi-dimensional arrays without having to know the exact structure beforehand.

<?php

function processArray($array) {
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            processArray($value); // Recursively call the function for nested arrays
        } else {
            // Manipulate the value here (e.g. echo or modify it)
            echo $key . ': ' . $value . PHP_EOL;
        }
    }
}

// Example of using the function with a multi-dimensional array
$data = [
    'name' => 'John',
    'age' => 30,
    'address' => [
        'street' => '123 Main St',
        'city' => 'New York'
    ]
];

processArray($data);

?>