Laravel 8 replaceRecursive() {#collection-method}
这个方法类似 replace
,但是会以递归的形式将数组替换到具有相同键的元素中:
$collection = collect(['Taylor', 'Abigail', ['James', 'Victoria', 'Finn']]);
$replaced = $collection->replaceRecursive(['Charlie', 2 => [1 => 'King']]);
$replaced->all();
// ['Charlie', 'Abigail', ['James', 'King', 'Finn']]