Tag Archives: php count_chars not working

PHP count_chars Function


PHP count_chars Function: It returns the characters and no of times used in the string.


How to use PHP count_chars Function?


count_chars(string,mode)

String : Input String
Mode : Defines the return mode. Following mode types are available.

0 – Array in key and value pair ASCII Value as key and number of occurrences as value.
1 – Array in key and value pair ASCII Value as key and number of occurrences as value only lists occurrences greater than zero.
2 – Array in key and value pair ASCII Value as key and number of occurrences as value only lists occurrences equal to zero.
3 – A string with all the different characters which have been used.
4 – A string with all characters which have not been used.

PHP count_chars Function Example 1

$string = "ABCA";
$s = count_chars($string,1);
print_r($s);

Try it »

In the Result below the ASCII value is key and The No of occurrence at value in array.
Output of the above example will be :

PHP count_chars Function

PHP count_chars() Function

PHP count_chars Function Example 1

$string = "ABCA";
$s = count_chars($string,3);
echo $s;

Try it »

PHP count_chars Function

PHP count_chars () Function