如何得到一个字符串中哪个字符出现的次数最多
a target=_blank href=http://list.qq.com/cgi-bin/qf_invite?id=08f814f703c7b4139f32b06cc2f7c0c1fd1b46f032c64622 rel=nofollow/a a href=http://qita.in/bMv target=_blank rel=nofollowimg alt=填写您的邮件地址,订阅我们的精彩内容:

$str=”asdfgfdas323344##$\$fdsdfg*$**$*$**$$443563536254fas”;//任意长度字符串 //解法一(最快速的解法,但是基本功要扎实) $arr=str_split($str); $arr=array_count_values($arr); arsort($arr); print_r($arr); //解法二(对逻辑能力有一定要求) $arr=str_split($str); $con=array(); foreach ($arr as $v){ if (!@$con[$v]){ @$con[$v]=1; }else{ @$con[$v]++; } } arsort($con); print_r($con); //解法三 $arr=str_split($str); $unique=array_unique($arr); foreach ($unique as $a){ $arr2[$a]=substr_count($str, $a); } arsort($arr2); print_r($arr2);
- 上一篇:具有通用性二维数组排序算法函数
- 下一篇:XML与数据格式进行转换类(PHP版)
精彩图集
精彩文章