pluck方法

获取集合中给定对应的所有值。

$collection = collect([
    ['product_id' => 'prod-100', 'name' => 'Desk'],
    ['product_id' => 'prod-200', 'name' => 'Chair'],
]);

$plucked = $collection->pluck('name');

$plucked->all(); // ['Desk', 'Chair']

也可以通过传入第二个参数来指定生成的集合的键:

$plucked = $collection->pluck('name', 'product_id');

$plucked->all(); // ['prod-100' => 'Desk', 'prod-200' => 'Chair']
Copyright © http://blog.webfsd.com 2018 all right reserved,powered by Gitbook该文件修订时间: 2019-05-21 04:55:26

results matching ""

    No results matching ""