How can recursive functions be utilized in PHP for array manipulation?

Recursive functions can be utilized in PHP for array manipulation when dealing with multidimensional arrays or nested structures. By using a recursive function, you can iterate through each element of the array, and if an element is itself an array, you can call the function recursively on that sub-array. This allows you to perform operations on all elements of the array, regardless of their depth within the structure.

function manipulateArray($array) {
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            $array[$key] = manipulateArray($value);
        } else {
            // Perform desired operation on the element
            $array[$key] = $value * 2;
        }
    }
    return $array;
}

// Example usage
$array = [1, 2, [3, 4, [5, 6]]];
$manipulatedArray = manipulateArray($array);
print_r($manipulatedArray);