1 /** 2 * 二维数组分组 3 * @param [type] $arr [二维数组] 4 * @param [type] $key [键名] 5 * @return [type] [新的二维数组] 6 */ 7 public function arrayGroupBy($arr, $key){ 8 $grouped = array(); 9 foreach ($arr as $value) { 10 $grouped[$value[$key]][] = $value; 11 } 12 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 } 分组前数据格式: array:5 [ 0 => array:22 [ "name" => "Jackie Ma8" "avatar" => "http:/