PHP sizeof()Functions
Examples
Returns the number of elements in the array:
<?php
$cars=array("Volvo","BMW","Toyota");
echo sizeof($cars);
?>
$cars=array("Volvo","BMW","Toyota");
echo sizeof($cars);
?>
Run Example »
Definition and Usage
The sizeof() function returns the number of elements in an array.
The sizeof() function iscount()an alias of the function.
Syntax
sizeof(array,mode);
| Parameter | Description |
|---|---|
| array | Required. Specifies the array to count. |
| mode | Optional. Specifies the mode of the function. Possible values:
|
Technical Details
| Return value: | Returns the number of elements in the array. |
|---|---|
| PHP Version: | 4+ |
More Examples
Example 1
Recursively count the number of elements in the array:
<?php
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . sizeof($cars)."<br>";
echo "Recursive count: " . sizeof($cars,1);
?>
$cars=array
(
"Volvo"=>array
(
"XC60",
"XC90"
),
"BMW"=>array
(
"X3",
"X5"
),
"Toyota"=>array
(
"Highlander"
)
);
echo "Normal count: " . sizeof($cars)."<br>";
echo "Recursive count: " . sizeof($cars,1);
?>
Run Example »
Complete PHP Array Reference Other Extensions