I have an array in the following format:
array("Vancouver FIR"=>array("data:data:data:data", "more:data", "even:more:data"), "Toronto FIR"=>array("data", "more:data"));
This array in reality is much larger and changes every three minutes.
I need this array to be sorted by the count() of the associative array keys. Furthermore if the count() is the same, they need to be sorted alphabetically.
I have tried using usort/uksort with no success?? This is mostly because one provides you with the values and one provides you with the keys, but in this case I need both. I am looking into making my own sorting algorithm but don't know where to start. Any suggestions?? Thanks in advance
What I have tried:
usort($sorted, function($x, $y) {
if (count($x) == count($y)) {
return strcmp(key($x),key($y));
} else {
return $x > $y ? -1 : 1;
}
});