Laravel 8 Arr::pluck() {#collection-method}
2021-07-19 10:18 更新
Arr::pluck
函数从数组中检索给定键的所有值:
use Illuminate\Support\Arr;
$array = [
['developer' => ['id' => 1, 'name' => 'Taylor']],
['developer' => ['id' => 2, 'name' => 'Abigail']],
];
$names = Arr::pluck($array, 'developer.name');
// ['Taylor', 'Abigail']
你也可以指定结果的键:
use Illuminate\Support\Arr;
$names = Arr::pluck($array, 'developer.name', 'developer.id');
// [1 => 'Taylor', 2 => 'Abigail']
以上内容是否对您有帮助:
更多建议: