Laravel - Collections - Method Replacerecursive

This method works like replace, but it will recur into arrays and apply the same replacement process to the inner values:

    
    $collection = collect([
        'Taylor',
        'Abigail',
        [
            'James',
            'Victoria',
            'Finn'
        ]
    ]);
    
    $replaced = $collection->replaceRecursive([
        'Charlie',
        2 => [1 => 'King']
    ]);
    
    $replaced->all();
    
    // ['Charlie', 'Abigail', ['James', 'King', 'Finn']]