如何使用PHP在空格或无空格的字符串中打印最大重复单词?

e.g. "helloworld hello world hello"

In above string "hello" is repeated 3 times in a string that is the maximum occurred word in the string.

So, output should be "hello"

Can you help me with this? I need the solution using PHP.

Try something like this:

$word = 'helloworld hello world hello';
$all = str_word_count($word,1);
$count = [];

foreach ($all as $wrd)
        $count[$wrd] = substr_count ($word, $wrd);

$max = max($count);

foreach($count as $key => $val)
    if ($val == $max)
        echo $key;