Skip to content

Instantly share code, notes, and snippets.

@zephster
Created April 26, 2012 17:21
Show Gist options
  • Save zephster/71888a897159835ce4f3 to your computer and use it in GitHub Desktop.
Save zephster/71888a897159835ce4f3 to your computer and use it in GitHub Desktop.
arbitrary uksort()
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