Jump to content

Php most common ints in array


bobert5696

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.