PHP之多维数组的指定多个字段排序

  • Post author:
  • Post category:php


/**
 * 多维数组的指定多个字段排序
 */
protected static function sortArrByManyField(){
    $args = func_get_args();
    if(empty($args)){
        return null;
    }
    $arr = array_shift($args);
    if(!is_array($arr)){
        throw new Exception("第一个参数不为数组");
    }
    foreach($args as $key => $field){
        if(is_string($field)){
            $temp = array();
            foreach($arr as $index=> $val){
                $temp[$index] = $val[$field];
            }
            $args[$key] = $temp;
        }
    }
    $args[] = &$arr;//引用值
    call_user_func_array('array_multisort',$args);
    return array_pop($args);
}



版权声明:本文为netuser1937原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。