1 / * * 2 * grouping two-dimensional array . 3 * @param [type] $ ARR [two-dimensional array] . 4 * @param [type] Key $ [key name] . 5 * @return [type] [new two-dimensional array ] . 6 * / . 7 public function arrayGroupBy ( $ ARR , $ Key ) { . 8 $ Grouped = Array (); . 9 the foreach ( $ ARR AS $ value ) { 10 $ Grouped [ $ value [ $ Key ]] [] = $ value ; . 11 } 12 is IF (func_num_args() > 2) { 13 $args = func_get_args(); 14 foreach ($grouped as $key => $value) { 15 $parms = array_merge($value, array_slice($args, 2, func_num_args())); 16 $grouped[$key] = call_user_func_array('array_group_by', $parms); 17 } 18 } 19 return $grouped; 20 }
Before the packet data format:
array:5 [ 0 => array:22 [ "name" => "Jackie Ma8" "avatar" => "http://fooku.oss-cn-hongkong.aliyuncs.com/Content/UserHeadImage/2018-04-05/Thumbnail/b6d97aa1-1a90-42fd-80f2-1e33e41d808a.png" "last_company" => "广州陪我公司" "last_position" => "前端工程师" "job_type" => "风控专员" "channel" => "boss直聘" ] 1 => array:22 [ "name" => "Jackie Ma9" "avatar" => "http://fooku.oss-cn-hongkong.aliyuncs.COM / Content / UserHeadImage / 2018-04-05 / Thumbnail The / b6d97aa1-1a90-42fd-80f2-1e33e41d808a.png " " job_type "=>" wind control commissioner. " " last_company "=>" Guangzhou company with me, " " last_position "=>" front-end engineers " "channel" => "boss straight employ" ] 2 => Array : 22 is [ "name" => "Jackie MA10" "Avatar" => "http://fooku.oss-cn-hongkong.aliyuncs.com/Content /UserHeadImage/2018-12-26/Thumbnail/5b4dc79d-81a1-494b-b2a5-be8164635ab3.png " " last_company "=>" Guangzhou talents Co., Ltd. " " last_position "=>" customer Service " " job_type "=>" financial salary statistics " " Channel "=>" Zhaopin " ] 3 => Array : 22 [ " name "=>" Jackie Ma12 " " Avatar "=>" HTTP: //fooku.oss-cn-hongkong.aliyuncs.COM / Content / UserHeadImage / 2018-12-26 / Thumbnail The / 5b4dc79d-81a1-494b-b2a5-be8164635ab3.png " Avatar "=>" http://fooku.oss-cn-hongkong.aliyuncs.com/Content/UserHeadImage/2018-12-26/Thumbnail/5b4dc79d-81a1-494b-b2a5-be8164635ab3.png " " last_company "=> "Guangzhou talents Co., Ltd." " last_position "=>" Customer Service " " job_type "=>" Financial compensation statistics. " "Channel" => "Zhaopin" ] . 4 => Array : 22 is [ "name" => "Jackie Ma11" "Avatar" => "HTTP: //fooku.oss-cn- hongkong.aliyuncs.com/Content/UserHeadImage/2018-12-26/Thumbnail/5b4dc79d-81a1-494b-b2a5-be8164635ab3.png " " last_company "=>" Guangzhou talents Co., Ltd. " " last_position "=>" customer Service " "job_type" => "financial compensation statistics" "Channel" => "Zhaopin" ] ]
After the packet data format:
Array : 2 [ "BOSS straight employ" => Array : 2 [ 0 => Array : 22 is [ "name" => "Jackie Ma8" "Avatar" => "HTTP: //fooku.oss-cn-hongkong.aliyuncs .com / Content / UserHeadImage / 2018-04-05 / Thumbnail The / b6d97aa1-1a90-42fd-80f2-1e33e41d808a.png " " last_company "=>" Guangzhou accompany our " " last_position "=>" front-end engineers " " job_type " => "wind control Commissioner" "Channel" => "BOSS straight employ" ] . 1 => Array : 22 is [ "name" => "Jackie MA9" "avatar" => "http://fooku.oss-cn-hongkong.aliyuncs.com/Content/UserHeadImage/2018-04-05/Thumbnail/b6d97aa1-1a90-42fd-80f2-1e33e41d808a.png" "last_company" => "Guangzhou accompany me to the company,""name" => "Jackie Ma12" "last_position" => "front-end engineers" "job_type" => "wind control commissioner." "channel" => "boss straight employed" ] ] "Zhaopin" => Array : 3 [ 0 => Array : 22 [ "name" => "Jackie MA10" "Avatar" => "HTTP: // fooku. oss-cn-hongkong.aliyuncs.com/Content/UserHeadImage/2018-12-26/Thumbnail/5b4dc79d-81a1-494b-b2a5-be8164635ab3.png " " last_company "=>" Guangzhou talents Co., Ltd. " " last_position "= > "customer service" "job_type" => "financial compensation statistics" "Channel" => "Zhaopin" ] 1 => Array : 22 [ "avatar" => "http://fooku.oss-cn-hongkong.aliyuncs.com/Content/UserHeadImage/2018-12-26/Thumbnail/5b4dc79d-81a1-494b-b2a5-be8164635ab3.png" "last_company" => "Guangzhou talents Co., Ltd." "last_position" => "Customer Service" "job_type" => "Financial compensation statistics" "Channel" => "Zhaopin" ] 2 => Array : 22 [ "name" => "Jackie Ma11" "Avatar" => "http://fooku.oss-cn-hongkong.aliyuncs.com/Content/UserHeadImage/2018-12-26/Thumbnail/5b4dc79d-81a1-494b-b2a5-be8164635ab3. PNG " " last_company "=>" Guangzhou talents Co., Ltd. " " last_position "=>" customer Service " " job_type "=>" financial compensation statistics " " Channel "=>" Zhaopin " ] ] ]