Created
April 26, 2012 17:21
-
-
Save zephster/71888a897159835ce4f3 to your computer and use it in GitHub Desktop.
arbitrary uksort()
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
function custom_sort($a, $b) { | |
if ($a == $b) { return 0; } | |
$order = array("things", "i", "want", "in", "order"); | |
$position = array_search($a, $order); | |
$position2 = array_search($b, $order); | |
if ($position !== false && $position2 !== false) return ($position < $position2) ? -1 : 1; | |
if ($position !== false) { return -1; } | |
if ($position2 !== false) { return 1; } | |
return ($a < $b) ? -1 : 1; | |
} | |
//use | |
uksort($array_to_sort, "custom_sort"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment