PHP sizeof() Function

PHP sizeof Function


Definition :

In php Array funciton sizeof() function is inbuilt function.The sizeof() function is used to returns the number of elements in an array.

he sizeof() function is an alias of the count() function.

Syntax:

       sizeof(array, mode)

Parameters:

The sizeof() function accepts two parameters.

Parameter Description
array Required. Specifies an array or countable object.
mode Optional. If it is set to COUNT_RECURSIVE (or 1), sizeof() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array.

 

Example1 : Given below example returen and count the number of element of array

Output : 3

Example2 : following example demonstrates how to count all the elements in a multidimensional array recursively using the sizeof() function.

Output :

Normal count: 3
Recursive count: 8