I was wondering how I would go about displaying the most common values in an array, so far my script gives the single most common value but what if I wanted the 5 most common?
function array_most_common($array) {
$counted = array_count_values($array);
arsort($counted);
return(key($counted));
}
echo array_most_common($array);
Many thanks.
Seems like you have it. I’d simply modify your function to return the the whole array so you can perform whatever logic you want afterwards: