💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ $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 ] ] ~~~