English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

count() Function in PHP

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

Syntax

count(arr, mode)

parameter

  • arr-the specified array.

  • Pattern-Specify a pattern. Possible values are 0 or1.0: Do not count all elements,1: Count all elements.

returns

Thiscount()The function returns the number of elements in the array-

Example

Here is an example-

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

Output Result

2