1. 程式人生 > >php 二維陣列時間排序實現程式碼

php 二維陣列時間排序實現程式碼

function arraySort($arr, $keys, $type = 'asc') {

    $keysvalue = $new_array = array();

    foreach ($arr as $k => $v){

      $keysvalue[$k] = $v[$keys];

    }

    $type == 'asc' ? asort(

$keysvalue) : arsort($keysvalue);

    reset($keysvalue);

    foreach ($keysvalue as $k => $v) {

      $new_array[$k] = $arr[$k];

    }

    return $new_array;

  }

$arr[] =

array("name"=>"1","time"=>1) ;

$arr[] = array("name"=>"2","time"=>2);

arraySort($arr,"time","desc"<