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.
Syntax
Parameter
- 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
Example
The following example show to how the count() function can be used in PHP.
<html>
<body>
<h3 style="color: blue;">count() function example in PHP</h3>
<?php
$a[0] = 'Nitin';
$a[1] = 'Sachin';
$a[2] = 'Pallavi';
$a[3] = 'Pratibha';
$result = count($a);
echo "Total number of element in array is : ".$result;
?>
</body>
</html>
|
Output
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