Improvements to merge arrays in PHP with the same key values for a field
Here is the implementation code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 |
/** * * Description of parameters * * key names with the same key value $key * * $array represents the original array * * $start representative $array[0][$key] * * $newkey the same key name for the same key value **/ 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; } |
http://www.bkjia.com/PHPjc/966370.html www.bkjia.com true http://www.bkjia.com/PHPjc/966370.html techarticle improvements to merge arrays with the same key values for a field in PHP the following is the implementation code:? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23/** * * Description of Parameters ...