<?php
$str = "Hello friend, Hello good good today!";
$count = array();
$words = array();
$cnt = str_word_count($str, 1);
foreach ($cnt as $val){
$i = 0;
$term = false;
foreach ($words as $word){
if ($word === $val){
$count[$i]++;
$term = true;
break;
}
$i++;
}
if ($term)
continue;
$words[$i] = $val;
$count[$i] = 1;
}
print_r($cnt);
print_r('<br/>');
$max = -1;
$resultWords = array();
$resultCount = array();
$i = 0;
foreach ($count as $c){
if ($max == $c){
$resultWords[] = $words[$i];
$resultCount[] = $c;
}else if ($max < $c){
$resultWords = array();
$resultCount = array();
$resultWords[] = $words[$i];
$resultCount[] = $c;
$max = $c;
}
$i++;
}
foreach ($resultWords as $result){
print_r($result.' '.$max.'<br/>');
}
?>
try using my code above. Hope it will work. If the most recurring word is only one word, then that word along with number of occurrence of that word will be display. If there is more than one word, all that words will be displayed as long as the number of occurrence.