The function is_iterable checks whether the contents of a variable is an iterable value.
bool is_iterable ( mixed $value )
Sr.No | Parameter & Description |
---|---|
1 |
value The value to check |
This function returns true if value is iterable, false otherwise. This function verifies 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
PHP 7.1 and above
Following example demonstrates return values with different types of variables −
<?php //array $a = [4, 5, 6]; echo "a is "; var_dump(is_iterable($a)); echo "<br>"; //array object $b = new ArrayIterator([1, 2, 3]); echo "b is "; var_dump(is_iterable($b)); echo "<br>"; //int $c = 3; echo "c is "; var_dump(is_iterable($c)); echo "<br>"; //object $d = new stdClass(); echo "d is "; var_dump(is_iterable($d)); echo "<br>"; ?>
This will produce following result −
a is bool(true) b is bool(true) c is bool(false) d is bool(false)