Thursday, 25 September 2014

count in PHP

PHP count() function is utilized to count the elements from an array, or the properties of an object.

Syntax:

count(array,mode)
 
Parameters description: 
array : Required. Specifies the array or object to count.
mode : Optional. Specifies the mode of the function.
     Possible values:
  • 0 - Default. Does not detect multidimensional arrays (arrays within arrays)
  • 1 - Detects multidimensional arrays
Tip :This function may return 0 if a variable isn't set, yet it might also return 0 if a variable holds an empty array. The isset() function might be utilized to test if a variable is set.
Note : This parameter was included PHP 4.2

Example:

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

O/P:

5

0 comments:

Post a Comment