PHP COUNT() FUNCTIONS - PHP LESSON 14 STUDENTSBLOG100 - Anna University Multiple Choice Questions

PHP COUNT() FUNCTIONS - PHP LESSON 14 STUDENTSBLOG100


By using php count() function we can count the number of elements present inside an array. The contents may be a string or integer or a character, it is not a problem. By using count() function we can count the number of values present inside the array.

Syntax:
count($array_name,mode);

Note : $array_name is mandatory and mode is not mandatory . Two modes used are 0,1. These modes are used in multidimensional arrays. 0 Does not count all elements of multidimensional arrays and 1 counts all elements of multidimensional array.

Example:
Output:
5

Example using modes in Multidimensional Array
Output:
Normal count: 3
Using 1 in count: 13

In the above example program, when the mode is not used, it reports 3 as output. That is it counts only the first array's elements.
When the mode "1" is used, it reports 13 as output. That is it counts all the elements of array. 1st array has three elements and 1st array's inner array has total of 10 elements. So total 3 + 10 = 13.

Lesson 13 Previous | Main Page | Next Lesson 15

No comments:

Post a Comment