I have an array of strings and I am looking for a way to find the most common string in the array.
$stuff = array(\'orange\',\'banana\', \'apples\',\'orange\');
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
$c = array_count_values($stuff);
$val = array_search(max($c), $c);