企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ $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 ] ] ~~~