array_multisort

function sorting_by_sale($arrUsers, $direction="desc"){
        if(empty($arrUsers)){
            return $arrUsers;
        }

        $direArr = array("desc"=>'SORT_DESC', 'asc'=>"SORT_ASC");
        
        $sort = array(  
            'direction' => $direArr[$direction], //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序  
            'field'     => 'sale_total',       //排序字段  
        );  
        $arrSort = array();  
        foreach($arrUsers AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']], constant($sort['direction']), $arrUsers);  
        }  
        
        return $arrUsers;
    }

 

posted @ 2016-06-15 16:33  天道酬勤,坚持!  阅读(235)  评论(0编辑  收藏  举报