Computer >> Computer tutorials >  >> Programming >> PHP

count() function in PHP


The count() function counts elements in an array, or properties in an object. It returns the number of elements in an array.

Syntax

count(arr, mode)

Parameters

  • arr − The specified array.

  • mode − Specifies the mode. Possible values are 0 or 1. 0: Do not count all the elements, 1: Count all the elements.

Return

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

Example

The following is an example −

<?php
   $products = array("Electronics","Footwear"); echo count($products);
?>

Output

2