PHP » Arrays » count()

Syntax:
int count(mixed var [, int mode])
var
The var for which the number of elements is wanted.
mode
Whether to count the array recursively.

Returns the size of an array.

This function returns the number of elements in an array. If the parameter provided to count() is not an array, 1 will be returned. The mode parameter is available in PHP 4.2.0 and up. If it is set to one, the elements in the array are counted recursively, which can be useful for multidimensional arrays.

Examples

Code:
<?php

print count(array("one", "two", "three")) . "<br>";
print count("one");

?>
Output:
3
1
Explanation:

This example shows count() in use on an array and a string.

See Also: