Skip to content

Kirby 5.0.4

A::keyBy()

Takes an array and makes it associative by an argument. If the argument is a callable, it will be used to map the array. If it is a string, it will be used as a key to pluck from the array.

A::keyBy(array $array, callable|string $keyBy): array

Parameters

Name Type Default
$arrayrequired array no default value
$keyByrequired callableorstring no default value

Return type

array

Parent class

Kirby\Toolkit\A

Examples

$array = [['id'=>1], ['id'=>2], ['id'=>3]];
$keyed = A::keyBy($array, 'id');