Sorry if this question already exists.
I have a question can you help me.
Only use strlen function and array. Can you make programming count number of character occurrences in a string with PHP (Character not repeat). Similar to create a new array_count_values function that available in php.
Eg:
$input = 'lorem lis pum';
Output:
l appeared 2 times;
o appeared 1 times;
r appeared 1 times;
...
This is my code when using available function array_count_values and it's worked.
$a = str_split($str, 1);
foreach (array_count_values($a) as $key => $value) {
if ($key === ' ') {
$key = '_';
}
echo $key.'appeared '.$value.' times<br>';
}
Thanks for read.