Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP sizeof() Function

PHP sizeof() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Return the number of elements in an array:

Run Example »


Definition and Usage

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

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


Syntax

sizeof(

array,mode

);

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

    Technical Details

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

    More examples

    Example 1

    Count the elements of an array recursively:

    array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "Normal count: " . sizeof($cars)."
    "; echo "Recursive count: " . sizeof($cars,1); ?>

    Run Example »


    PHP Array ReferenceComplete PHP Array Reference Manual