php 二維數組時間排序實現代碼

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

    $keysvalue = $new_array = array();io

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

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

    }im

    $type == 'asc' ? asort($keysvalue) : arsort($keysvalue);sort

    reset($keysvalue);co

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

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

    }return

    return $new_array;

  }

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

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

arraySort($arr,"time","desc");

相關文章
相關標籤/搜索