使用 collection
,怎么把before转化成after
$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']
]
];