This question listened to me all night, so I came up with another option. This is a universal and reusable solution that will work by any criteria. (At least anyone that I can think of.) Here you can find.
<?php
function multi_sort(&$array, $criteria, $defaults=array()){
$cache = array();
foreach($criteria as &$c){
uasort($c, function($a,$b){
return strlen($b) - strlen($a);
});
}
$findIndex = function($str, $values){
foreach($values as $index=>$value){
if( stripos($str, $value) !== FALSE ){
return $index;
}
}
return NULL;
};
$calculateValue = function($str) use ($criteria, $findIndex, $defaults, $cache){
if( !isset($cache[$str]) ){
$parts = array();
foreach($criteria as $i=>$c){
$parts[$i] = $findIndex($str, $c);
if( $parts[$i] === NULL ){
$parts[$i] = (isset($defaults[$i]) ? $defaults[$i] : 1000);
}
$parts[$i] = str_pad($parts[$i], 4, '0');
}
$cache[$str] = implode($parts, '-');
}
return $cache[$str];
};
$compare = function($a, $b) use ($calculateValue){
$av = $calculateValue($a);
$bv = $calculateValue($b);
return $av > $bv;
};
usort($array, $compare);
}
$list = array(
'Bold', 'ExtraBold', 'ExtraLight', 'Light', 'Medium', 'Regular', 'SemiBold', 'Thin', 'Condensed Bold', 'Expanded Black', 'Condensed ExtraLight', 'Expanded Thin'
);
$sort_criteria = array(
array("Expanded", "Standard", "Condensed"),
array("Black", "ExtraBold", "Bold", "SemiBold", "Medium", "Regular", "Light", "Thin", "ExtraLight")
);
multi_sort($list, $sort_criteria, array(1));
print_r($list);
$animals = ['big cat', 'small dog', 'big dog', 'small cat'];
$sort_criteria = [['dog','cat'], ['big','small']];
multi_sort($animals, $sort_criteria);
print_r($animals);