php array count

Share Button

PHP count() Function


Return the number of elements in an array:

echo count($cars);

Definition and Usage

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




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)

Technical Details

Return Value: Returns the number of elements in the array
PHP Version: 4+
Changelog: The mode parameter was added in PHP 4.2

More Examples

Example 1

Count the array recursively:

);echo “Normal count: ” . count($cars).”<br>”;
echo “Recursive count: ” . count($cars,1);
Share Button