I’ve got an array that has a numbered key, followed by a name, in this syntax:
[50-Aname] => arraydata
[45-Anothername] => arraydata
[45-Bname] => arraydata
[30-Cname] => arraydata
By using krsort(), I can get the array to sort as a high-score table (Counting backwards) . But this means, if they have the same number, Bname will appear before Anothername as it is ordering reverse alphabetically as well.
So, is there a way to sort the numbers largest to smallest, but alphabetically as well?
You can use
uksort()and define a function as a comparator of your keys, based on which the sorting will be carried.In short, that function should split the key by the “-” and then use the 2 components to create a total order.
The documentation of
uksort: http://www.php.net/manual/en/function.uksort.php