<?php class a{ /** *$array 数组 *$keys 需要进行排序的字段 *$type 排序规则 */ function array_sort($array,$keys,$type=‘asc‘){ //$array为要排序的数组,$keys为要用来排序的键名,$type默认为升序排序 $keysvalue = $new_array = array(); foreach ($array as $k=>$v){ $keysvalue[$k] = $v[$keys]; } if($type == ‘asc‘){ asort($keysvalue); }else{ arsort($keysvalue); } reset($keysvalue); foreach ($keysvalue as $k=>$v){ $new_array[$k] = $array[$k]; } return $new_array; } } $hotcat =array( 0 =>array("name"=>"zhangsan","points"=>"98"), 1 =>array("name"=>"lisi","points"=>"47"), 2 =>array("name"=>"wangwu","points"=>"88"), 3 =>array("name"=>"zhaoliu","points"=>"69"), 4 =>array("name"=>"xiaoba","points"=>"100"), ); $a = new a(); $data = $a->array_sort($hotcat,‘points‘,‘desc‘); var_dump($data);
原文:http://www.cnblogs.com/hgj123/p/4916775.html