PHP - Function count()


Advertisements


Syntax

count($array, $mode );

Definition and Usage

Count elements in an array, or properties in an object.

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

Parameters

Sr.No Parameter & Description
1

array(Required)

It specifies an array

2

mode(Optional)

It specifies the mode of the function.

Return Value

It returns the number of elements in an array.

Example

Try out following example −

<?php
   $a[0] = 1;
   $a[1] = 3;
   $a[2] = 5;
   $result = count($a);
   print($result);
?> 

This will produce the following result −

3

php_function_reference.htm

Advertisements