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

How to host application on server new way

 copy the htacess from public to root copy the server.php from public to root but rename to index.php htacess <IfModule mod_rewrite.c>...