I want to sort a multidimensional array by appearances of the number of subarrays.
This is my multidimensional array (it could hold any subarrays holding any values randomly ordered, this is just for testing purposes):
$items = array (
array ("00008", "Metal", "Melvins", "Working With God", "Sub Pop", "SP 009"),
array ("00019", "LP", "Ray Parker", "The Other Woman", "EMI", "EMI02"),
array ("00019", "LP", "Ray Parker", "The Other Woman", "EMI", "EMI02"),
array ("00019", "LP", "Ray Parker", "The Other Woman", "EMI", "EMI02"),
array ("00021", "Techno", "Laurent Garnier", "Water Planet", "F Communications", "SDB00015"),
array ("00056", "LP", "Communards", "Communards", "RCA", "E 342-F"),
array ("00056", "LP", "Communards", "Communards", "RCA", "E 342-F"));
So that after sorting the multidimensional array becomes:
$items = array (
array ("00019", "LP", "Ray Parker", "The Other Woman", "EMI", "EMI02"),
array ("00019", "LP", "Ray Parker", "The Other Woman", "EMI", "EMI02"),
array ("00019", "LP", "Ray Parker", "The Other Woman", "EMI", "EMI02"),
array ("00056", "LP", "Communards", "Communards", "RCA", "E 342-F"),
array ("00056", "LP", "Communards", "Communards", "RCA", "E 342-F"),
array ("00008", "Metal", "Melvins", "Working With God", "Sub Pop", "SP 009"),
array ("00021", "Techno", "Laurent Garnier", "Water Planet", "F Communications", "SDB00015"));
The purpose is that the subarray occuring three times appears first, followed by the subarray appearing two times. All the subarrays occurring one time can appear in random order.
Can it be done using a one-liner?
For example: sorting out the uniques can be done like this:
$uniques = array_intersect_key ($items, array_unique (array_map ("serialize", $items)));
Many thanks for helping me out!
00019is first because there are three sub arrays with that ID-like thing.