二维数组排序可以用php内置函数
1 <?php 2 $arr = array( 3 4 array('name'=>'zhangsan','age'=>26,'gender'=>'male','height'=>180), 5 array('name'=>'zhangsan','age'=>21,'gender'=>'female','height'=>156), 6 array('name'=>'zhangsan','age'=>59,'gender'=>'male','height'=>178) 7 8 9 ); 10 11 12 function array_sort($arr=array(),$key='',$sort=0){ 13 14 $arr_key = array(); 15 foreach ($arr as $k=>$v) { 16 $arr_key[$k] = $v[$key]; 17 18 } 19 ($sort == 0)?asort($arr_key):arsort($arr_key); 20 21 $return_arr = array(); 22 foreach ($arr_key as $k=>$v) { 23 24 $return_arr[$k] = $arr[$k]; 25 26 } 27 28 return $return_arr; 29 } 30 31 $arr_key = array_sort($arr,'age',0); 32 33 print_r($arr_key); 34 35 36 ?>