- var_dump: documentation ( source)
- ctype_alpha: documentation ( source)
- ksort: documentation ( source)
- str_split: documentation ( source)
<?php
function count_char($str) {
$chars = str_split($str);
$char_counter = array();
foreach($chars as $char) {
if (ctype_alpha($char)) {
if (!isset($char_counter[$char])) {
$char_counter[$char] = 1;
} else {
++$char_counter[$char];
}
}
}
ksort($char_counter);
return $char_counter;
}
var_dump(count_char("Hello World"));