Created
June 30, 2014 09:30
-
-
Save vibhasbhingarde/2965ad9a6608e8f66be8 to your computer and use it in GitHub Desktop.
Sorting Multidimesional array
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
function cmp($a, $b) { | |
if ($a['TotalEarnings'] == $b['TotalEarnings']) { | |
return 0; | |
} | |
if ($_GET['sortby'] == "earnings"): | |
$orderBy = ($_GET['order'] == 'a') ? "DESC" : "ASC"; | |
endif; | |
if ($orderBy == "DESC"): | |
return ($a['TotalEarnings'] < $b['TotalEarnings']) ? -1 : 1; | |
else: | |
return ($a['TotalEarnings'] > $b['TotalEarnings']) ? -1 : 1; | |
endif; | |
} | |
usort($mediaArray, "cmp"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment