Skip to content
Advertisement

How to group PHP arrays by key before sorting by another key?

I have an array that contains the key counted and placement which I am trying to group by before I sort. The array should be first sorted by counted and then, for each duplicate counted, should then sort by placement.

JavaScript

My expected output here would be:

JavaScript

I have tried to usort to achieve this:

JavaScript

But this gives me an unexpected result. Everything I try seems to not work, any ideas would be appreciated.

Advertisement

Answer

Since you prefer using usort so this is my answser

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement