count the characters in string

$string = "fdkfhkhihrekfbkfndfnnfns";
$chars = str_split($string);
$charCounts = [];

foreach ($chars as $char) {
if (array_key_exists($char, $charCounts)) {
$charCounts[$char]++;
} else {
$charCounts[$char] = 1;
}
}

print_r($charCounts);

No comments:

Post a Comment

sun dried potato procedure

  Sun-Dried Potato Chips Recipe  https://www.youtube.com/watch?v=e_PVvAU77Qs , recipe for potato sun dried chips 1) ist peel off the potato ...