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 | callable orstring |
no default value |
Return type
array
Parent class
Examples
$array = [['id'=>1], ['id'=>2], ['id'=>3]];
$keyed = A::keyBy($array, 'id');