下面是实现代码:
function combine_same_val($array,$start,$key,$newkey){
static $new;
foreach($array as $k=>$v){
if($v[$key]==$start){
$new[$v[$newkey]][] = $v;
unset($array[$k]);
continue;
}
}
sort($array);
if(count($array)!==0){
combine_same_val($array,$array[0][$key],$newkey);
}
return $new;
}
static $new;
foreach($array as $k=>$v){
if($v[$key]==$start){
$new[$v[$newkey]][] = $v;
unset($array[$k]);
continue;
}
}
sort($array);
if(count($array)!==0){
combine_same_val($array,$array[0][$key],$newkey);
}
return $new;
}