I had a project I was working on yesterday and I needed to sort out an array in order of most to least repeated, so I came up with this:
$array = array_count_values($array); array_multisort($array, SORT_DESC);
If you don't want the frequency that they occur in as the value, you can do this:
$array = array_count_values($array); array_multisort($array, SORT_DESC); $array = array_keys($array);
Hope this helps someone. ![]()




December 16th, 2007 at 3:47 am
Usually if you have many items and use a database, it's faster to use SQL's ORDER BY function.
December 16th, 2007 at 7:23 pm
Yes, this is generally only good for things like regular expressions or similar items.