PHP count() function

PHP count() function

The count() function in PHP is used to count all elements in the specified array or something in an object.

Syntax

Parameter

array_or_countable(required)– This parameter represents the input array or countable object.

mode(optional)– This parameter is used to specify the mode. The possible mode values are as follows:

  • If it is set to integer value 0 (default value), it does not count all elements of multidimensional arrays
  • If set to integer value 1, it counts all the elements of multidimensional arrays recursively.

Return

This function returns the number of elements in the array.

It returns 1, if the parameter “array_or_countable” is neither an array nor an object.

It returns 0, if array_or_countable is NULL.

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output

Example 5

Output