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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP count() Function Usage and Example

PHP Array Function Manual

The count() function calculates the number of elements in an array or the number of properties in an object

Syntax

count($array, $mode);

Definition and Usage

Count the number of elements in an array or properties in an object.

If the optional mode parameter is set to COUNT_RECURSIVE (or1),then count() will recursively count the array.

Parameter

Serial NumberParameters and Description
1

array (required)

It specifies an array

2

mode (optional)

It specifies the function mode.

Return Value

It returns the number of elements in the array.

Online Example

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

<?php
   $a[0] = 1;
   $a[1] = 3;
   $a[2] = 5;
   $result = count($a);
   print($result);
?>
Test and see‹/›

Output Result:

3

  PHP Array Function Manual