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

AI Tools

 Midjourney oter.ai aiva googlegemin dall-e copilot jasper copilot openaiplayground