Example 1 — Count Items
Find out how many items are in an array.
<?php
$fruits = ["apple", "banana", "cherry"];
echo "Fruits: ", count($fruits), PHP_EOL;
echo "Empty: ", count([]), PHP_EOL; How It Works
- Create an array of three fruits.
- count() returns the number of elements, which is 3.
- An empty array has no items, so its count is 0.
- echo prints both numbers.

