The sizeof() function returns the number of elements in an array.
The sizeof() function is an alias of the count() function.
PHP sizeof() Function has the following syntax.
sizeof(array,mode);
Parameter | Is Required | Description |
---|---|---|
array | Required. | Specifies the array |
mode | Optional. | Specifies the mode. |
Possible values for model:
Value | Description |
---|---|
0 | Default. Does not count all elements from multidimensional arrays |
1 | Counts the array recursively for all the elements of multidimensional arrays |
<?php
$cars=array("A","B","C");
echo sizeof($cars);
?>
The code above generates the following result.
Count the array recursively:
<?php
$cars=array("A"=>array("A1","A2"),
"B"=>array("B1","B2"),
"C"=>array("C1")
);
echo "Normal count: " . sizeof($cars)."\n";
echo "Recursive count: " . sizeof($cars,1);
?>
The code above generates the following result.