~~~
$data =
[
[
["title"] => "客房服务",
["id"] => 4,
["count"] => 1,
],
[
["title"] => "设备报修",
["id"] => 5,
["count"] => 1,
],
[
["title"] => "客房服务",
["id"] => 4,
["count"] => 1,
]
];
$result =[];
foreach($data as $val){
$key = $val['id'].'_'.$val['title'];
if(!isset($result[$key])){
$result[$key] = $val;
}else{
$result[$key]['count'] += $val['count'];
}
}
$result = array_values($result);
~~~
可得到如下的数据:
~~~
[
[
"title": "客房服务",
"id": 4,
"count": 2
],
[
"title": "设备报修",
"id": 5,
"count": 1
]
]
~~~