PHP count() Function

PHP count Function


Definiton:

The count() function count all elements in an array, or something in an object.

Syntax:

The basic syntax of the count() function is given with:

    count(arraymode);

Parameter:
Parameter Description
array Required. Specifies the array
mode Optional. Specifies the mode. Possible values:
  • 0 - Default. Does not count all elements of multidimensional arrays
  • 1 - Counts the array recursively (counts all the elements of multidimensional arrays)

 Example1 : we can see below example return the number no elements an array 

Output : 3

Example2 : Count the array recursively

Output : Normal count : 3
                Recursive count : 8