Created
January 21, 2013 12:10
-
-
Save msysyamamoto/4585625 to your computer and use it in GitHub Desktop.
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 | |
function array_sort(&$array) | |
{ | |
return usort($array, 'array_compare'); | |
} | |
function array_asort(&$array) | |
{ | |
return uasort($array, 'array_compare'); | |
} | |
function array_compare($a, $b) | |
{ | |
if (!is_array($a) || !is_array($b)) { | |
if ($a > $b) { | |
return 1; | |
} | |
if ($a < $b) { | |
return -1; | |
} | |
return 0; | |
} | |
reset($a); | |
reset($b); | |
while (true) { | |
$va = each($a); | |
$vb = each($b); | |
if ($va === false && $vb === false) { | |
return 0; | |
} | |
if ($va === false) { | |
return -1; | |
} | |
if ($vb === false) { | |
return 1; | |
} | |
$cmp = array_compare($va['value'], $vb['value']); | |
if ($cmp !== 0) { | |
return $cmp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment