PHP is_iterable() Function

PHP 可用的函数PHP Available Functions

is_iterable()The function is used to check whether a variable is an iterable value.

PHP Version Requirement: PHP 7 >= 7.1.0

Syntax

bool is_iterable ( mixed $var )

Parameter description:

  • $var: The variable to be checked, can be an array or an object implementing the Traversable interface.

Return Value

Returns TRUE if the specified variable is an iterable value, otherwise returns FALSE.

Example

Example

<?php 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) ?>

The output result is:

bool(true)
bool(true)
bool(true)
bool(false)
bool(false)

PHP 可用的函数PHP Available Functions

Other Extensions