Arrays\each()

higher-order terminal accepts iterable returns Closure
((int|string, T) → void) → (Iterable → void)
At a glance — The "for side effects only" iterator — no return value. Terminal; the whole source is consumed.

Creates a Closure that iterates over an array or iterable, invoking the callback with each (key, value) pair for its side effect. Returns void.

/**
  * @param callable(int|string $key, mixed $value):void $func
  * @return Closure(iterable<int|string, mixed>):void
  */
Arrays\each(callable $func): Closure

Returned Closure

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

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

Examples

Partial Application

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

$log = Arrays\each(function ($key, $value) {
    echo "$key => $value\n";
});

$log(['a' => 1, 'b' => 2]);
// a => 1
// b => 2

Details

Arrays Functions

Releated Array iteration Functions