15 1 0 4000 1 https://codeblock.co.za 300 true 0

count()

0 Comments

Programming Language

PHP [Versions: 4, 5, 7, 8]

Syntax

Typical Usage

Getting the number of elements in a PHP array.


Accepted Parameters

  • 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.

Notes

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.

Examples

Example 1

<?php
$cars = ['focus', 'fiesta', 'kuga', 'mustang'];
print_r( count($cars) );

The result is 4. Four elements in the array.

Similar Functions in Other Languages

Was This Helpful?

Previous Post
implode()
Next Post
array_combine()

0 Comments

Leave a Reply