Created
January 27, 2015 14:04
-
-
Save JBlond/57ad9b40b4ded06d08d0 to your computer and use it in GitHub Desktop.
sort array by key
This file contains 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 | |
/* | |
Array | |
( | |
[0] => Array | |
( | |
[hashtag] => a7e87329b5eab8578f4f1098a152d6f4 | |
[title] => Flower | |
[order] => 3 | |
) | |
[1] => Array | |
( | |
[hashtag] => b24ce0cd392a5b0b8dedc66c25213594 | |
[title] => Free | |
[order] => 2 | |
) | |
[2] => Array | |
( | |
[hashtag] => e7d31fc0602fb2ede144d18cdffd816b | |
[title] => Ready | |
[order] => 1 | |
) | |
) | |
*/ | |
function aasort (&$array, $key) { | |
$sorter=array(); | |
$ret=array(); | |
reset($array); | |
foreach ($array as $ii => $va) { | |
$sorter[$ii]=$va[$key]; | |
} | |
asort($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