💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] # 问题 ~~~ $before = [ ['id' => 1, 'love' => 'apple'], ['id' => 1, 'love' => 'orange'], ['id' => 1, 'love' => 'banana'], ['id' => 2, 'love' => 'pea'], ['id' => 2, 'love' => 'apple'], ['id' => 3, 'love' => 'banana'], ]; $after = [ [ 'id' => 1, 'love' => ['apple', 'orange', 'banana'] ], [ 'id' => 2, 'love' => ['pea', 'apple'] ], [ 'id' => 3, 'love' => ['banana'] ] ]; ~~~ # 解决 ~~~ collect($before)->groupBy('id')->map(function($item){ return [ 'id' => $item->first()['id'], 'love' => $item->pluck('love')->all() ]; })->all(); ~~~ ~~~ return array_values(collect($before)->groupBy('id')->map(function($item){ return [ 'id' => $item->first()['id'], 'love' => $item->pluck('love')->all() ]; })->all()); ~~~