is_iterable()

is_iterable() — Verify that the contents of a variable is an iterable value.

Built-in function of PHP 8.5. The manual lists it as available in PHP 7 >= 7.1.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 accepted by the iterable pseudo-type, i.e. that it is either an array or an object implementing Traversable

Signature

is_iterable(mixed $value): bool

Parameters

ParameterTypeWhat it takes
$valuemixedThe value to check

Return value

Returns true if value is iterable, false otherwise.

Example

A runnable snippet:

var_dump(is_iterable([1, 2, 3])); // bool(true) var_dump(is_iterable(new ArrayIterator([1, 2, 3]))); // bool(true) var_dump(is_iterable((function () { yield 1; })())); // bool(true) var_dump(is_iterable(1)); // bool(false) var_dump(is_iterable(new stdClass())); // bool(false)

See also

is_array()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page is_iterable() (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.