对二维数组排序

function array_sort($arr, $row, $type='asc'){
  $newArr = array();
  foreach($arr as $v){
    $newArr[$v[$row]] = $v;
  } 

  if($type == 'asc'){
    ksort($newArr);
  }else if($type == 'asc'){
    krsort($newArr);
  }else{
    echo "error";
  }
  return $newArr;
}

$info = array(
  array('id' => 2, 'name' => 'zhangsan', 'age' => 23),
  array('id' => 5, 'name' => 'lisi', 'age' => 28),
  array('id' => 3, 'name' => 'apple', 'age'=> 17)
);

print_r(array_sort($info, 'name'));

  

posted @ 2017-06-15 17:27  蚂蚁力量  阅读(140)  评论(0编辑  收藏  举报