转载地址: http://blog.qita.in/?post=467 $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);
复制代码