Home  >  Article  >  php教程  >  php二维数组根据键值排序

php二维数组根据键值排序

PHP中文网
PHP中文网Original
2016-05-23 17:10:131078browse

php代码

    public function sort($arr,$sort,$v){    //$arr->数组   $sort->排序顺序标志   $value->排序字段

        if($sort == "0"){                   //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序  
                $sort = "SORT_ASC";
        }elseif ($sort == "1") {
                $sort = "SORT_DESC";
        }
         
        foreach($arr as $uniqid => $row){  
            foreach($row as $key=>$value){                     
                    $arrsort[$key][$uniqid] = $value;
                }  
            }  
            if($sort){
            array_multisort($arrsort[$v], constant($sort), $arr);  
        }       
         return $arr;
    }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn