How to get index value of highest repetition in a string in php

1

I'd like to get the highest repetition index value in a string.

String example: 4,1,2,1,1,1,3,1,2,5,3 .

The result should be "1" , as it repeats 5 times.

    
asked by anonymous 05.03.2018 / 15:50

1 answer

2

Use the array_count_values() function:

$array = array(4,1,2,1,1,1,3,1,2,5,3);
$total = array_count_values($array);

So, $total will be an array as below:

$total
(
    [1] => 5
    [2] => 2
    [3] => 2
    [4] => 1
    [5] => 1
)
    
05.03.2018 / 15:59