I'm trying to first sort by quantity in Rank and if the quantity is equal then sort numerically by Rank.
It might sound complicated but here is the pseudo-code I envision
- First sort arrays by the number of repeated values in Rank.
- If number of repeated values is equal sort numerically by the value in Rank.
I guess its kinda recursive seeing as the 2nd part is performed on all sub-arrays.
I've been trying usort but I can't get it so see the count of repeated rank values in the array. Multisort doesn't seem to fit either.
Example:
Array ( [0] => Array ( [Rank] => 7 [Suit] => Hearts ) [1] => Array ( [Rank] => 3 [Suit] => Hearts ) [2] => Array ( [Rank] => 6 [Suit] => Spades ) [3] => Array ( [Rank] => 10 [Suit] => Spades ) [4] => Array ( [Rank] => 3 [Suit] => Spades ) [5] => Array ( [Rank] => 6 [Suit] => Hearts ) [6] => Array ( [Rank] => 2 [Suit] => Clubs ) )
According to my algorithm
Array ( [0] => Array ( [Rank] => 6 [Suit] => Hearts ) [1] => Array ( [Rank] => 6 [Suit] => Spades ) [2] => Array ( [Rank] => 3 [Suit] => Spades ) [3] => Array ( [Rank] => 3 [Suit] => Hearts ) [4] => Array ( [Rank] => 10 [Suit] => Spades ) [5] => Array ( [Rank] => 7 [Suit] => Hearts ) [6] => Array ( [Rank] => 2 [Suit] => Clubs ) )