foreach ($arr as $key => $value) { $new_array[$value['typeId']][] = $value; }
$res =[]; //想要的结果 foreach ($arr as $k => $v) { //dd($v); $res[$v['cardId'].$v['typeId']]['cardId'] = $v['cardId']; $res[$v['cardId'].$v['typeId']]['typeId'] = $v['typeId']; $res[$v['cardId'].$v['typeId']]['cardBatch'][] = $v['cardBatch']; } dd(array_merge($res));