📅  最后修改于: 2022-03-11 14:48:32.811000             🧑  作者: Mango
$arr = json_decode($str, true);
$names = array_column($arr, "name");
$codes = array_column($arr, "code");
foreach(array_unique($names) as $name){
$new[$name] = array_intersect_key($codes, array_intersect($names, [$name]));
}
var_dump($new);