Home >Backend Development >PHP Tutorial >Improvements in php about merging arrays with the same key value of a certain field, php field_PHP tutorial
The following is the implementation code:
/** **关于参数的说明 **$key键值相同的键名 **$array代表原数组 **$start代表$array[0][$key] **$newkey代表相同键值相同的键名 **/ 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],$key,$newkey); } return $new; }