sizeof
count alias
The sizeof()
function calculates the number of units in an array or the number of attributes in an object.
sizeof()
function is an alias for the count()
function.
Note: When the variable is not set, or the variable contains an empty array, the function returns 0. You can use the isset() variable to test whether the variable is set.
Returns the number of elements in the array:
<?php $cars = array ( "Volvo" , "BMW" , "Toyota" ) ; echo sizeof ( $cars ) ; ?>
Try it yourself
Recursively calculate the number of elements in an array:
<?php $cars = array ( "Volvo" => array ( "XC60" , "XC90" ) , "BMW" => array ( "X3" , "X5" ) , "Toyota" => array ( "Highlander" ) ) ; echo "General Count:" . sizeof ( $cars ) . "<br>" ; echo "Recursive Counting:" . sizeof ( $cars , 1 ) ; ?>
Try it yourself
sizeof ( array , mode ) ;
parameter | describe |
---|---|
array | Required. Specify array. |
mode |
Optional. Prescribed mode. Possible values:
|