cnsnms

302 经验值

小姐姐.......你声音好甜。Jelly,退下吧!哈哈哈哈

        $demo = [
            ["group"=>"A",
                "list"=>[
                    ["name"=>"1"],
                    ["name"=>"2"],
                    ["name"=>"3"],]
            ],
            ["group"=>"B",
                "list"=>[
                    ["name"=>"4"],
                    ["name"=>"5"],
                    ["name"=>"6"],]
            ]
        ];
        $middle = '';

        dd(
            collect($demo)->flatten()->map(
                function($val) use(&$middle){
                    if(is_numeric($val)) {
                        return ['name'=>$val,'group'=>$middle];
                    }else{
                        $middle = $val;
                    }
                })->reject(
                function($val){
                    return !is_array($val);
                }
            )
        );

善做笔记,好记性不如烂笔头,定期温故!

@jelly vip半年会员已经付款,请查收!!!!