这是在不使用字符串函数的情况下计算字符串出现次数的小片段。
<?php
$str ='1234567891222222222233333332';
$count = 0;
$ones='';
$twos='';
$threes='';
while(isset($str[$count])){
//echo $str[$count];
if($str[$count]== 1)
$ones += count($str[$count]);
if($str[$count]== 2)
$twos += count($str[$count]);
if($str[$count]== 3)
$threes += count($str[$count]);
++$count;
}
echo 'total number of 1\'s = '.$ones.'<br/>';
echo 'total number of 2\'s = '.$twos.'<br/>';
echo 'total number of 3\'s = '.$threes.'<br/>';
?>
请任何人都可以有效地缩短代码...