HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP sizeof() Function

PHP Array Reference PHP Array Reference

Example

Return the number of elements in an array:

<?php
$cars=array("Volvo","BMW","Toyota");
echo sizeof($cars);
?>

Run example »

Definition and Usage

The sizeof() function returns the number of elements in an array.

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


Syntax

sizeof(array,mode);

Parameter Description
array Required. Specifies the array
mode Optional. Specifies the mode. Possible values:
  • 0 - Default. Does not count all elements of multidimensional arrays
  • 1 - Counts the array recursively (counts all the elements of multidimensional arrays)

Technical Details

Return Value: Returns the number of elements in the array
PHP Version: 4+


More Examples

Example 1

Count the array recursively:

<?php
$cars=array
  (
  "Volvo"=>array
  (
  "XC60",
  "XC90"
  ),
  "BMW"=>array
  (
  "X3",
  "X5"
  ),
  "Toyota"=>array
  (
  "Highlander"
  )
  );

echo "Normal count: " . sizeof($cars)."<br>";
echo "Recursive count: " . sizeof($cars,1);
?>

Run example »


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE