程序来查找字符在PHP中的字符串中出现了多少次
示例
<?php
$str = "welcome to nhooo.com";
$str = str_replace(" ","",$str);
$arr = str_split($str);
foreach ($arr as $key =>$val){
if (!isset($output[$val])){
$output[$val] = 1;
}
else{
$output[$val] += 1;
}
}
foreach($output as $char =>$number){
echo $char." ".'appears '. $number." ".'times'."\n";
}
?>输出结果
w appears 1 times e appears 2 times l appears 2 times c appears 1 times o appears 4 times m appears 1 times t appears 4 times u appears 1 times r appears 1 times i appears 2 times a appears 1 times s appears 1 times p appears 1 times n appears 1 times
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特