basic-problem / count-char-string-using-array.php

COunt Char String Using Array

<?php
function countCharacter($str)
{
    return array_count_values(str_split($str));
}

print_r(countCharacter("hello"));
// Output: Array ( [h] => 1 [e] => 1 [l] => 2 [o] => 1 )

COunt Char String Using Array | basic-problem | Study Notes | Ferdyhape