Вы можете сделать это -
$string = "abcaaabbcccccdaasvvbbvvtteesgggg";
// Split string by character and convert to array
$temp = str_split($string);
// Count values present in array
array_count_values($temp);
Выход
Array ( [a] => 6 [b] => 5 [c] => 6 [d] => 1 [s] => 2 [v] => 4 [t] => 2 [e] => 2 [g] => 4 )
array_count_values ()
str_split ()
Для непрерывных событий
// split and create array with unique characters
$new = array_unique(str_split($string));
$chars = [];
foreach($new as $c) {
// regex check for character's multiple occurrences
preg_match_all("/($c)\\1+/", $string, $matches);
// Store the count
$chars[$c] = count($matches[0]);
}
print_r($chars);
Outpur
Array
(
[a] => 2
[b] => 2
[c] => 1
[d] => 0
[s] => 0
[v] => 2
[t] => 1
[e] => 1
[g] => 1
)