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

Hey Folks, It’s Worse Than We Thought — Claude’s Privacy Mess Just Got Bigger

  What started as a leak of shared Claude chats has turned into something much bigger — and much worse. The same thing is now happening with...