How to display most repeated elements in the array?

Hello, there is a array:
$arr = array('blue', 'blue', 'green', 'yellow', 'red', 'red', 'red', 'orange', 'orange', 'orange');
which blue is repeated 2 times, red 3 times, orange - 3 times.

How to display only those elements that are repeated the MOST number of times (if the number is not known)? That is, if there were any element, for example purple, which was repeated 4 times, the output is
June 14th 19 at 18:15
4 answers
June 14th 19 at 18:17
  1. To count the number of repetitions
  2. To sort in descending order of number of repetitions
  3. Take the first element of the array from the previous paragraph
June 14th 19 at 18:19
array_count_values max
June 14th 19 at 18:21
$arr = array('blue', 'blue', 'green', 'yellow', 'red', 'red', 'red', 'orange', 'orange', 'orange');
$valuesQuantity = array_count_values($arr);
arsort($valuesQuantity);
$maxFrequentElement = key($valueQuantity);
June 14th 19 at 18:23
$arr = array('blue', 'blue', 'green', 'yellow', 'red', 'red', 'red', 'orange', 'orange', 'orange');
$counted_arr = array_count_values($arr);
$max_repeats_count = max($counted_arr);

foreach($counted_arr as $key => $value)
{
 if($value === $max_repeats_count) echo $key, '<br>';
}

Find more questions by tags PHP