is_countable()
is_countable() — Verify that the contents of a variable is a countable value.
Built-in function of PHP 8.5. The manual lists it as available in PHP 7 >= 7.3.0, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Verify that the contents of a variable is an array or an object implementing Countable
Signature
is_countable(mixed $value): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $value | mixed | The value to check |
Return value
Returns true if value is countable, false otherwise.
Example
A runnable snippet:
var_dump(is_countable([1, 2, 3])); // bool(true) var_dump(is_countable(new ArrayIterator(['foo', 'bar', 'baz']))); // bool(true) var_dump(is_countable(new ArrayIterator())); // bool(true) var_dump(is_countable(new stdClass())); // bool(false)
Changelog
| Version | Change |
|---|---|
| 7.3.0 | is_countable() has been added. |
See also
is_array(), is_object(), is_iterable(), is_bool()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page is_countable() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.