Definition
The count() function returns the number of elements in an array.
Syntax
count(array, mode)
Parameters
Parameter | Description |
---|---|
array |
Required. Specifies the array. |
mode |
Optional. Specifies the mode. Possible values: 0 - Default. Does not count all elements of multidimensional arrays 1 - Counts the array recursively (counts all the elements of multidimensional arrays). |
Example
<?php
// Example 1
$cities = array("New York", "Salt Lake", "Tokyo");
echo count($cities) . "<br>";
// Example 2
$persons = array(
"Mark" => array(22, "USA"),
"Jeff" => array(32, "Germany"),
"Mike" => array(28, "Japan")
);
echo count($persons) . "<br>";
echo count($persons, 1) . "<br>";