I have this array:
Array ( 'jan' => 2, 'feb' => 1, 'mar' => 2, 'apr' => 1 )
..and I want to return:
Array ('jan', 'mar')
As in, find the 2 elements with the highest count and put them in an array. What is the simplest way to achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
max()to get the maximum value, andarray_keys()to get an array containing the keys that had that value.