How to use count in PHP
In this article, I will explain how the count() function can be used in PHP.
count() function in PHP
- The count() function is used to count the elements of an array, or the properties of an object.
- The count() function may return 0 if a variable isn't set.
- In count() function, isset() function can be used to test if a variable is set.
- array array is required parameter. it's determine the array or object to count.
mode mode is optional parameter. it's determine mode of the function. Possible values
- 0 - it is the default value. It does not detect multidimensional array.
- 1 - It detects multidimensional arrays
The following example show to how the count() function can be used in PHP.
<h3 style="color: blue;">count() function example in PHP</h3>
$a = 'Nitin';
$a = 'Sachin';
$a = 'Pallavi';
$a = 'Pratibha';
$result = count($a);
echo "Total number of element in array is : ".$result;
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here