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

create cartoon video using ai

  https://www.piclumen.com/ using this we can crate cartoon photos https://hailuoai.video/ its not free upto 1000 points we canuse it for fr...