1、需求
- 将相同 apply_id 的 apply_remark 用
;
拼接
$r = [
['apply_id' => 1, 'apply_remark' => 'xxx'],
['apply_id' => 1, 'apply_remark' => 'xxx2'],
['apply_id' => 2, 'apply_remark' => 'xxx3'],
];
2、编码
$r = [
['apply_id' => 1, 'apply_remark' => 'xxx'],
['apply_id' => 1, 'apply_remark' => 'xxx2'],
['apply_id' => 2, 'apply_remark' => 'xxx3'],
];
$rs = collect($r)->groupBy('apply_id')
->map(function ($group) {
return [
'apply_id' => $group->first()['apply_id'],
'apply_remark' => $group->pluck('apply_remark')->implode(';'),
];
})
->values()
->toArray();
dd($rs);
3、结果
array:2 [
0 => array:2 [
"apply_id" => 1
"apply_remark" => "xxx;xxx2"
]
1 => array:2 [
"apply_id" => 2
"apply_remark" => "xxx3"
]
]
标签:laravel,remark,group,xxx,collect,apply,array,id
From: https://www.cnblogs.com/pine007/p/17982619