PHP [Versions: 4, 5, 7, 8]
Getting the number of elements in a PHP array.
- array (array) (Required): The array you wish to to count. May also be something in an object.
- mode (integer) (Optional) (Default = COUNT_NORMAL): If set to 1 or COUNT_RECURSIVE, you can get the count all the elements of a multi-dimensional array.
Return Value(s)Returns an integer with the amount of elements in the array.
count() can detect recursion to avoid an infinite loop, but will emit an E_WARNING every time it does (in case the array contains itself more than once) and return a count higher than may be expected.
<?php $cars = ['focus', 'fiesta', 'kuga', 'mustang']; print_r( count($cars) );
The result is 4. Four elements in the array.
Used In Projects
Similar Functions in Other Languages