根据二维数组相同值来分组

//根据二维数组相同值来分组
    public static function array_group_by($arr, $key)
    {
        $grouped = [];
        foreach ($arr as $value) {
            $grouped[$value[$key]][] = $value;
        }
        if (func_num_args() > 2) {
            $args = func_get_args();
            foreach ($grouped as $key => $value) {
                $parms = array_merge([$value], array_slice($args, 2, func_num_args()));
                $grouped[$key] = call_user_func_array('array_group_by', $parms);
            }
        }
        //分数排序
        foreach ($grouped as &$_group) {
            $arrSort = array();  
            foreach($_group as $r_key => $r_val){  
                foreach($r_val as $key => $val){  
                    $arrSort[$key][$r_key] = $val;  
                }
            }  
        }
        return $grouped;
    }

 

posted @ 2017-03-15 20:16  代罪羊  阅读(902)  评论(0编辑  收藏  举报