Example 1 — Countable and Not Countable
Check an array, an object, a string and a number.
<?php
var_dump(is_countable([1, 2, 3]));
var_dump(is_countable(new ArrayObject([1])));
var_dump(is_countable("abc"));
var_dump(is_countable(42)); How It Works
- Every array can be counted, so the first call is true.
- ArrayObject implements the Countable interface, so it is also countable.
- A string is not countable. Use strlen() for its length.
- A number cannot be counted either.

