PHP array multiple sort – by value then by key?

As Scott Saunders hints in his comment to David’s solution, you can use the array_keys() and array_values() functions to get rid of the loop. In fact, you can solve this in one line of code:

array_multisort(array_values($arrTags), SORT_DESC, array_keys($arrTags), SORT_ASC, $arrTags);

Leave a Comment