Created
July 22, 2013 06:11
-
-
Save WenLiangTseng/6051629 to your computer and use it in GitHub Desktop.
PHP 排序一個二維陣列的方式,將一個二維陣列依據裡面的 key 來排序
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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