return new array with the same key

foreach ($arr as $key => $value) {
    $new_array[$value['typeId']][] = $value;
}

$res =[]; //desired result
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));

Guess you like

Origin blog.csdn.net/qq_58778333/article/details/132189037