|
countCounts all elements in an array or in a Countable object Description
int count(Countablearray
$value , int $mode = COUNT_NORMAL )Counts all elements in an array when used with an array. When used with an object that implements the Countable interface, it returns the return value of the method Countable::count. Parameters
Return Values
Returns the number of elements in Changelog
Examples
Example #1 count example
The above example will output: int(3) int(3)
Example #2 count non Countable|array example (bad example - don't do this)
The above example will output: int(3) int(0) int(1) Output of the above example in PHP 7.2: int(3) Warning: count(): Parameter must be an array or an object that implements Countable in … on line 12 int(0) Warning: count(): Parameter must be an array or an object that implements Countable in … on line 14 int(1) Output of the above example in PHP 8: int(3) Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable .. on line 12
Example #3 Recursive count example
The above example will output: int(8) int(2)
Example #4 Countable object
The above example will output: int(2) |