Home > php教程 > PHP源码 > body text

php二维数组根据键值排序

PHP中文网
Release: 2016-05-23 17:10:13
Original
1085 people have browsed it

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;
    }
Copy after login

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!