PHP Tutorial - PHP sizeof() Function


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.



ParameterIs RequiredDescription
arrayRequired.Specifies the array
modeOptional.Specifies the mode.

Possible values for model:

0Default. Does not count all elements from multidimensional arrays
1Counts the array recursively for all the elements of multidimensional arrays

Example 1

echo sizeof($cars);

The code above generates the following result.

Example 2

Count the array recursively:


echo "Normal count: " . sizeof($cars)."\n";
echo "Recursive count: " . sizeof($cars,1);

The code above generates the following result.