成语大全网 - 汉语词典 - php如何统计字符串“很长一串英文”中各个单词出现的频率?

php如何统计字符串“很长一串英文”中各个单词出现的频率?

<?php

$word="很长一串英文";

$total=array();

foreach(explode(" ",$word) as $v){

isset($total[$v])?$total[$v]++:$total[$v]=1;

}

foreach($total as $k=>$v){

echo $k." 出现次数 ".$v."<br>";

}

>