String de-weight and count the characters of each character

Source: Internet
Author: User

Suddenly see the number of statistics string and the problem of the weight, the heart of a thought to try the next ha. Also take the function of the array comes out, as a look at the memory of it

$a= ' EEEFFFKKKHJK ';/*********** The number of occurrences of each character in the statistics string ************/$total=Array(); for($i= 0;$i<strlen($a);$i++){    if(isset($total[$a[$i]])) {        $total[$a[$i]] +=1; } Else {        $total[$a[$i]] = 1; }}Var_dump($total);/*********** string de-weight *********/$b=Array(); for($j= 0;$j<strlen($a);$j++){    if(!In_array($a[$j],$b)) {            Array_push($b,$a[$j]); }}Var_dump($b);$exa=Array(' E ', 2,3,3, ' e ');/*********** The number of occurrences of each value in the statistics array ************/$totals=array_count_values($exa);Var_dump($totals);/*********** Remove repeating elements in an array ************/$uni=Array_unique($exa);Var_dump($uni);

Finally, add a method, that is, the string is explode to the array, and then the use of arrays function statistics and de-weight, but also can be counted and de-weight string

String de-weight and count the characters of each character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.