The function to use:
Str_split: Splits a string into an array. A similar function explode () function splits a string into arrays. Array_count_values: Used to count the occurrences of all values in the array.
Arsort: Reverses the array and maintains the index relationship.
It is primarily used to sort the associative arrays that are important for the cell order. $str = "asdfgfdas323344##$\ $fdsdfg *$**$*$**$$443563536254fas";//string of any length
Copy CodeThe code is as follows:
$arr =str_split ($STR);
$arr =array_count_values ($arr);
Arsort ($arr);
Print_r ($arr);
Output:
Copy CodeThe code is as follows:
Array
(
[$] = 7
[3] = 6
[*] = 6
[4] = 5
[F] = 5
[s] = 4
[D] = 4
[5] = 3
[A] = 3
[6] = 2
[2] = 2
[G] = 2
[#] = 2
)
The second method:
The function to use:
Array_unique: Removes duplicate values from the array. Substr_count: Calculates the number of occurrences of a substring in a string.
Copy CodeThe code is as follows:
$str = "asdfgfdas323344##$\ $fdsdfg *$**$*$**$$443563536254fas";//string of any length
$arr =str_split ($STR);
$unique =array_unique ($arr);
foreach ($unique as $a) {
$arr 2[$a]=substr_count ($str, $a);
}
Arsort ($arr 2);
Print_r ($arr 2);
http://www.bkjia.com/PHPjc/325755.html www.bkjia.com true http://www.bkjia.com/PHPjc/325755.html techarticle function used: Str_split: Splits a string into an array. A similar function explode () function splits a string into arrays. Array_count_values: Used to count the number of occurrences of all values in an array ...