A::pluck()
Plucks a single column from an array
A::pluck(array $array, string $key): array
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| $arrayrequired | array |
no default value | The source array |
| $keyrequired | string |
no default value | The key name of the column to extract |
Return type
array
The result array with all values from that column.
Parent class
Examples
$array[] = [
'id' => 1,
'username' => 'homer',
];
$array[] = [
'id' => 2,
'username' => 'marge',
];
$array[] = [
'id' => 3,
'username' => 'lisa',
];
var_dump(A::pluck($array, 'username'));
// result: ['homer', 'marge', 'lisa'];