Home >>PHP Array Functions >PHP sizeof() Function
PHP sizeof() function is used to count the number of elements present in the given input array or any other countable object. It accepts two parameters $array and $mode. It returns an integer value as result which represents the number of elements present in the given input array.
Syntax:
sizeof($array, $mode);
Parameter | Description |
---|---|
array | This is a required parameter. It defines the array. |
mode | This is an optional parameter. It defines the mode. |
Here is an example of sizeof() function in PHP:
<html> <body> <?php $x=array("A","B","C","D","E","F","G","H","I","J","K"); echo sizeof($x); ?> </body> </html>
Example 2:
<html> <body> <?php $x=array("A"=>array("1","2"),"B"=>array("3","4"),"C"=>array("5")); echo "Normal count: " . sizeof($x)."<br>"; echo "Recursive count: " . sizeof($x,1); ?> </body> </html>