时间:2021-07-01 10:21:17 帮助过:36人阅读
$testStr = 'rewruo ewjrewm' . PHP_EOL . 'hcywer国bg gfaaf d中国国国s国rew';
$testStr = preg_replace('/\s/', '', $testStr);
preg_match_all('/./u', $testStr, $strList);
$charCount = array_count_values($strList[0]);
arsort($charCount);
$maxCount = current($charCount);
foreach($charCount as $char => $count){
if($count < $maxCount){
break;
}
echo $char . '出现了 ' . $count . ' 次
';
}
$testStr = 'rewruo ewjrewm' . PHP_EOL . 'hcywer国bg gfaaf d中国国国s国rew';r 出现了 5 次
$testStr = preg_replace('/\s/', '', $testStr);
preg_match_all('/./u', $testStr, $strList);
$strList = array_count_values($strList[0]);
$r = array_keys($strList, $m = max($strList));
echo join($t=" 出现了 $m 次
", $r).$t;