Arrays\pick()

transformer variadic terminal accepts iterable returns Closure pure
...string → (Iterable → mixed[])
At a glance — Pluck a subset of keys out of a structure. Terminal on Generator input.

Creates a Closure that selects only the specified indexes/keys from an array or iterable.

/**
  * @param string ...$indexes The keys to keep.
  * @return Closure(iterable<int|string, mixed>):mixed[]
  */
Arrays\pick(string ...$indexes): Closure

Returned Closure

When Arrays\pick() 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.

$idAndName = Arrays\pick('id', 'name');

print_r($idAndName(['id' => 1, 'name' => 'Ada', 'secret' => 'xxx']));
// ['id' => 1, 'name' => 'Ada']

Details

Arrays Functions

Releated Array access Functions