bobert5696 Posted August 17, 2011 Share Posted August 17, 2011 Here is my situation, I have an array containing say 50 numbers in it ( array(1,2,3,4,5,6,7,8,9,10,etc etc) ) and there will be many duplicates in it. I am trying to return the top ten numbers in it, in order from greatest to least. I can return the most common one, but I need the most common ten. This is what I have tried: $final_results contains an array of numbers [0][10],[1][23],[2][0],[3][5] etc etc array_count_values($final_results) will return the number of times each number is duplicated in a new array, in the form [number][duplications] and it preserves the number Anything I do after that point replaces [number] with [0][1][2] for say the 3 most common if that makes sense Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/244978-php-most-common-ints-in-array/ Share on other sites More sharing options...
salathe Posted August 17, 2011 Share Posted August 17, 2011 Is there a question? Link to comment https://forums.phpfreaks.com/topic/244978-php-most-common-ints-in-array/#findComment-1258510 Share on other sites More sharing options...
AbraCadaver Posted August 17, 2011 Share Posted August 17, 2011 $counts = array_count_values($final_results); arsort($counts); $counts = array_slice(array_keys($counts), 0, 10); Link to comment https://forums.phpfreaks.com/topic/244978-php-most-common-ints-in-array/#findComment-1258638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.