pluck(value) : 返回指定key的值组成的集合
pluck(value, key) : 返回指定value,key的值组成的集合
$collection = collect([
['product_id' => 'prod-100', 'name' => 'Desk', 'price'=>10.2],
['product_id' => 'prod-200', 'name' => 'Chair', 'price'=>10.3],
]);
return $collection->pluck('name', 'product_id'); // prdocut_id值作为key,name的值作为value: {"prod-100":"Desk","prod-200":"Chair"}
return $collection->pluck('name'); // name值组成的集合: ["Desk","Chair"]
网友评论