Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
Created July 22, 2013 06:11
Show Gist options
  • Save WenLiangTseng/6051629 to your computer and use it in GitHub Desktop.
Save WenLiangTseng/6051629 to your computer and use it in GitHub Desktop.
PHP 排序一個二維陣列的方式,將一個二維陣列依據裡面的 key 來排序
<?php
function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
asort($sorter); //由低至高排序
//arsort($sorter); 由高至低排序
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
}
aasort($your_array,"order");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment