PHP get the item in an array that has the most duplicates PHP get the item in an array that has the most duplicates arrays arrays

PHP get the item in an array that has the most duplicates


$c = array_count_values($stuff); $val = array_search(max($c), $c);


Use array_count_values and get the key of the item:

<?php$stuff = array('orange','banana', 'apples','orange', 'xxxxxxx');$result = array_count_values($stuff);asort($result);end($result);$answer = key($result);echo $answer;?>

Output:

orange