PHP count() Function

Definition and Usage

The count() function returns the number of elements in an array.

Syntax

count(array,mode);

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)

Example

Return the number of elements in an array:
<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?> 
 
OUTPUT :