Arr::pluck

Posted on November 16, 2016

The Arr::pluck function will pluck a list of the given key / value pairs from the array.

You may also specify how you wish the resulting list to be keyed.

Example usage

$array = [
    ['developer' => ['id' => 1, 'name' => 'Taylor']],
    ['developer' => ['id' => 2, 'name' => 'Abigail']],
];

$array = Arr::pluck($array, 'developer.name');

// ['Taylor', 'Abigail'];

$array = Arr::pluck($array, 'developer.name', 'developer.id');

// [1 => 'Taylor', 2 => 'Abigail'];

Parameters

array $array

string|array $value

string|array|null $key

Return Value

array

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *