Skip to content

Instantly share code, notes, and snippets.

@nixonmedia
Created April 18, 2018 18:33
Show Gist options
  • Save nixonmedia/37952de27f1b4065b2b817f894dba999 to your computer and use it in GitHub Desktop.
Save nixonmedia/37952de27f1b4065b2b817f894dba999 to your computer and use it in GitHub Desktop.
function sortMyThings($things) {
uasort($things, function($left, $right) {
$l1 = strtoupper(clean($left['manufacturer']));
$r1 = strtoupper(clean($right['manufacturer']));
if (0 !== strcmp($l1, $r1)) return strcmp($l1, $r1) < 0? -1 : 1;
$l2 = strtoupper(clean($left['brand']));
$r2 = strtoupper(clean($right['brand']));
if (0 !== strcmp($l2, $r2)) return strcmp($l2, $r2) < 0? -1 : 1;
$l3 = !empty($left['type'])? $left['type'] : $left['title'];
$r3 = !empty($right['type'])? $right['type'] : $right['title'];
$l3 = strtoupper(clean($l3));
$r3 = strtoupper(clean($r3));
if (0 == strcmp($l3, $r3)) return 0;
return strcmp($l3, $r3) < 0? -1 : 1;
});
return $things;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment