Skip to content

Instantly share code, notes, and snippets.

@vibhasbhingarde
Created June 30, 2014 09:30
Show Gist options
  • Save vibhasbhingarde/2965ad9a6608e8f66be8 to your computer and use it in GitHub Desktop.
Save vibhasbhingarde/2965ad9a6608e8f66be8 to your computer and use it in GitHub Desktop.
Sorting Multidimesional array
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