Menu Riverview Church

COUNT

Count all elements in an array, or something in an object

SYNTAX

count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] ) : int

PARAMETERS

array_or_countable

An array or countable object.

mode

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

RETURN

Returns the number of elements in array_or_countable. When the parameter is neither an array nor an object with implemented Countable interface, 1 will be returned. There is one exception, if array_or_countable is NULL, 0 will be returned.

EXAMPLES

ARRAY_OR_COUNTABLE | ARRAY

3

ARRAY_OR_COUNTABLE | COUNTABLE

3

ARRAY_OR_COUNTABLE | FALSE

1

ARRAY_OR_COUNTABLE | NULL

0

MODE | COUNT_NORMAL

3

MODE | COUNT_RECURSIVE

5

PHP