PHP count_chars() Function

You are Here:

PHP count_chars()

The count_chars() function returns information about characters used in a string.

This function counts the number of occurrences of every byte-value (0 to 255) in string and returns it in various ways (depending upon the specified mode parameter).

Example

PHP Compiler
<?php $str = "PHP world"; echo count_chars($str, 3); ?>

Syntax

count_chars(str, mode)

Parameter Values

ValueTypeExplanation
strRequiredSpecifies a string to be examined.
modeOptionalSpecifies the return modes.
The following are the list of different modes:
  • 0 - an array with the byte-value as key and the frequency of every byte as value.
  • 1 - same as 0 but only byte-values with a frequency greater than zero are listed.
  • 2 - same as 0 but only byte-values 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.
Default value is 0.

Return Value

ValueExplanation
array | stringThe return value depends on the specified mode parameter.

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author