What are the potential pitfalls when using recursion in PHP for array manipulation?

Potential pitfalls when using recursion in PHP for array manipulation include the risk of infinite loops if not properly handled, increased memory usage as each recursive call creates a new stack frame, and potential performance issues for large arrays. To solve these issues, it is important to have a base case that stops the recursion, ensure proper error handling to prevent infinite loops, and consider the trade-offs between recursion and iterative approaches for array manipulation.

function recursiveArrayManipulation($array) {
    // Base case to stop recursion
    if (empty($array)) {
        return $array;
    }
    
    // Recursive call for array manipulation
    $element = array_shift($array);
    $manipulatedElement = manipulateElement($element);
    $manipulatedArray = recursiveArrayManipulation($array);
    
    return array_merge([$manipulatedElement], $manipulatedArray);
}