Arrays\replaceRecursive()

transformer variadic terminal accepts iterable returns Closure pure
...T[] → (Iterable → T[])
At a glance — Wraps array_replace_recursive(). Terminal on Generator input.

Creates a Closure that recursively replaces values in an array or iterable based on matching keys — like array_replace_recursive() but curried.

/**
  * @param mixed[] ...$with
  * @return Closure(iterable<int|string, mixed>):mixed[]
  */
Arrays\replaceRecursive(array ...$with): Closure

Returned Closure

When Arrays\replaceRecursive() is called, it returns the following Closure which can be used like a regular function.

/**
  * @param iterable<int|string, mixed> $source
  * @return mixed[]
  */
$function (iterable $source): array

Examples

Partial Application

This can be used to create a simple closure which can be used as a regular function.

$defaults = ['theme' => ['font' => 'Arial', 'size' => 12]];

$setFont = Arrays\replaceRecursive(['theme' => ['font' => 'Comic Sans']]);

print_r($setFont($defaults));
// ['theme' => ['font' => 'Comic Sans', 'size' => 12]]

Details

Arrays Functions

Releated Array manipulation Functions