|
|
Tutorials » Php »
|
Topic |
What is count_Chars Function?
|
|
Explanation |
|
In PHP, this function is used to return information about characters used in a string.
Syntax:
count_chars(string,mode)
In the above syntax for the given "string" , mode has values "0,1,2,3,4"
| MODE |
DESCRIPTION |
| "0" |
An array with the ASCII value as key and number of occurrences as value |
| "1" |
An array with the ASCII value as key and number of occurrences as value, only lists occurrences greater than zero |
| "2" |
An array with the ASCII value as key and number of occurrences as value, only lists occurrences equal to zero are listed |
| "3" |
A string with all the different characters used |
| "4" |
A string with all the unused characters |
Example:
<?php
$str = "Hey how are you!";
print_r(count_chars($str,1));
?>
Result:
Array (
[32] => 3
[33] => 1
[72] => 1
[97] => 1
[101] => 2
[104] => 1
[111] => 2
[114] => 1
[117] => 1
[119] => 1
[121] => 2
)
In the above example the string "$str" is displayed as an array with ASCII as the key and number of occurences as values.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|