时间:2021-07-01 10:21:17 帮助过:6人阅读
$data = '[ { "ClientId": 0, "RoleId": 2 }, { "ClientId": 1, "RoleId": 1 }, { "ClientId": 1, "RoleId": 4 } ]';$data = json_decode($data);
$data = '[ { "ClientId": 0, "RoleId": [2] }, { "ClientId": 1, "RoleId": [1,4] } ]';$data = json_decode($data);
$data = json_decode($data, true);$arr = array();foreach($data as $itm) { $arr[$itm['ClientId']]['ClientId'] = $itm['ClientId']; $arr[$itm['ClientId']]['RoleId'][] = $itm['RoleId'];}$arr = array_values($arr);