# count_chars()

This function in php is used to count the number to characters in any string.

here is the example of php **count_chars function**

<?

$data = “Best college in Australia, Colleges in Sydney“;

foreach (count_chars($data, 1) as $i => $val) {

echo “There were $val instance(s) of \”” , chr($i) , “\” in the string.\n”;

}

?>

Output will be:

There were 6 instance(s) of ” ” in the string.

There were 1 instance(s) of “,” in the string.

There were 1 instance(s) of “A” in the string.

There were 1 instance(s) of “B” in the string.

There were 1 instance(s) of “C” in the string.

There were 1 instance(s) of “S” in the string.

There were 2 instance(s) of “a” in the string.

There were 1 instance(s) of “c” in the string.

There were 1 instance(s) of “d” in the string.

There were 6 instance(s) of “e” in the string.

There were 2 instance(s) of “g” in the string.

There were 3 instance(s) of “i” in the string.

There were 5 instance(s) of “l” in the string.

There were 3 instance(s) of “n” in the string.

There were 2 instance(s) of “o” in the string.

There were 1 instance(s) of “r” in the string.

There were 3 instance(s) of “s” in the string.

There were 2 instance(s) of “t” in the string.

There were 1 instance(s) of “u” in the string.

There were 2 instance(s) of “y” in the string.

## Leave a Reply