PHP » GoLang |
login |
register |
about
|
count(PHP 4, PHP 5, PHP 7) count — Count all elements in an array, or something in an object DescriptionCounts all elements in an array, or something in an object. For objects, if you have SPL installed, you can hook into count() by implementing interface Countable. The interface has exactly one method, Countable::count(), which returns the return value for the count() function. Please see the Array section of the manual for a detailed explanation of how arrays are implemented and used in PHP. Parameters
Return Values
Returns the number of elements in Caution
count() may return 0 for a variable that isn't set, but it may also return 0 for a variable that has been initialized with an empty array. Use isset() to test if a variable is set. Examples
Example #1 count() example
<?php The above example will output: int(3) int(3) Warning: count(): Parameter must be an array or an object that implements Countable in … on line 12 // as of PHP 7.2 int(0) Warning: count(): Parameter must be an array or an object that implements Countable in … on line 14 // as of PHP 7.2 int(1)
Example #2 Recursive count() example
<?php Changelog
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|