Thursday, 25 September 2014

sizeof in PHP

PHP sizeof() function is used to count the elements from an array, or the properties of an object.
It is an alias to count() function.

Syntax:

sizeof(array,mode)
 
Parameters Description: 
array : Required. Determines the array or object count.
mode : Optional. Determines the mode of the function. Conceivable values:
  • 0 -Default. Does not detect multidimensional arrays (arrays within arrays)
  • 1 -Detects multidimensional arrays
Note : This parameter was added in PHP 4.2
Note : PHP sizeof() function may return 0 if a variable isn't set, but it may also return 0 if a variable contains an empty array.
           The isset() function can be used to test if a variable is set.

Example:

<?php
$daysarr = array( "Sunday","Monday","Tuesday","Wednesday","Thursday" );
$result= sizeof($daysarr);
echo $result;
?>

Output will be:

5

0 comments:

Post a Comment