I have an array of string keys with numeric values to be used to create a list of tags with the number of occurrences of each tag resembling this:
$arrTags = [
'mango' => 2,
'orange' => 4,
'apple' => 2,
'banana' => 3
];
I want to display the tags in a list with descending values, then the
tag names ascending to produce:
orange (4)
banana (3)
apple (2)
mango (2)
arsort() is not suitable because it will put mango before apple. I’m guessing that usort() may be the way, but I’m not finding a suitable example in the comments on php.net.
Have a look at examples #3:
http://php.net/manual/en/function.array-multisort.php
You’ll need to create two arrays to use as indexes; one made up of the original array’s keys and the other of the original array’s values.
Then use multisort to sort by text values (keys of the original array) and then by the numeric values (values of the original array).