Home >>PHP Array Functions >PHP sizeof() Function

PHP sizeof() Function

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 Values

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>
Output:
11

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>
Output:
Normal count: 3
Recursive count: 8

No Sidebar ads