Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function sizeof()


previous

Advertisements

Syntax

sizeof($array, $mode );

Definition and Usage

Count elements in an array, or properties in an object.

If the optional mode parameter 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. The default value for mode is 0. sizeof() does not detect infinite recursion.

Paramters

ParameterDescription
arrayRequired. Specifies an array
modeOptional. Specifies the mode of the function.

Return Value

Returns the number of elements in an array.

Example

Try out following example:

<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = sizeof($a);
print($result);
?> 

This will produce following result:

3

previous Printer Friendly

Advertisements


  

Advertisements