collection集合中有没有这样的方法?

collection 集合中有没有这样的方法,可以取出集合部分值,并且值为数组

<?php
public function test1(Request $request)
    {
        $collection = collect([
            [
                "a"=>1,
                "b"=>2,
                "c"=>3
            ],[
                "a"=>4,
                "b"=>5,
                "c"=>6
            ],[
                "a"=>7,
                "b"=>8,
                "c"=>9
            ]
        ]);

        //输出结果:
        //[
        //    1,
        //    4,
        //    7
        //]
        return $collection->pluck("a");

        //$collection->pluck(["a","b"]);
        //希望输出
        //[
        //    ["a"=>1,"b"=>2]
        //    ["a"=>4,"b"=>5]
        //    ["a"=>7,"b"=>8]
        //]
    }
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 9
$collection->map(function ($item) {
      Arr::forget($item, 'c');
      return $item;
})->all()
2年前 评论
houguang (楼主) 2年前
luyang (作者) 2年前

最简单的就是用 map 格式化下

2年前 评论

可以使用 Collection 的 macro 方法添加自定义的方法

2年前 评论
houguang (楼主) 2年前
godruoyi

看起来我们可以这样做,但如果直接用 collect 好像不得行。

file

2年前 评论
godruoyi (作者) 2年前
houguang (楼主) 2年前