Press "Enter" to skip to content

count_chars

PHP count_char Function

The count_chars() function counts the number of occurrences of each character in string (For example how many time an ASCII character occurs in a string ) returns result in various mode

SYNTAX

count_chars ( string $string [, int $mode = 0 ] )

Different Return Mode are :
Default is 0
0- an array key contain the ASCII value and number of occurrences as value.
1 -an array key contain the ASCII value and number of occurrences as value, with a frequency greater than zero are listed.
2 – an array key contain the ASCII value and number of occurrences as value, with a frequency equal to zero are listed.
3 – a string containing all unique characters is returned.
4 – a string containing all not used characters is returned.

Example for PHP count_char Function

<?php
$str = “w3htmlschool.com”;
print_r( count_chars($str,1));
?>