Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3, PHP 8.4 With Latest All Version Support.
`count()` Function in PHP 8.2, PHP 8.3 & PHP 8.4
The `count()` function in PHP is used to count the number of elements in an array or countable object.
Syntax
count(array|Countable $value, int $mode = COUNT_NORMAL): int
Example 1: Counting Elements in an Array
<?php $arr = [1, 2, 3, 4, 5]; echo count($arr); // Output: 5 ?>
Example 2: Counting Elements in a Multidimensional Array
<?php $multiArray = [ "A" => [1, 2, 3], "B" => [4, 5], "C" => [6] ]; echo count($multiArray); // Output: 3 (only counts top-level elements) echo count($multiArray, COUNT_RECURSIVE); // Output: 7 (counts all elements) ?>