Course Recommendation:
PHP sizeof() Function
Example
<?php Return the number of elements in an array: $cars=array("Volvo","BMW","Toyota");; ?>
echo sizeof($cars)
Definition and Usage
The sizeof() function calculates the number of units in an array or the number of properties in an object. The sizeof() function is count()
Alias of the function.Note:
When the variable is not set, or the variable contains an empty array, this function will return 0. You can use the isset() variable to test whether the variable is set.
Syntaxarraysizeof(mode);
, | Description |
---|---|
array | Required. Specify the array. |
mode |
Optional. Specify the mode. Possible values:
|
Technical Details
Return Value: | Return the number of elements in an array. |
PHP Version: | 4+ |
More Examples
Example 1
Recursively count the number of elements in an array:
<?php $cars=array ( "Volvo"=>array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "Regular Count: " . sizeof($cars)."<br>"; echo "Recursive Count: " . sizeof($cars,1); ?>