• PHP Video Tutorials

PHP - is_iterable() Function


Advertisements

Definition and Usage

The function is_iterable checks whether the contents of a variable is an iterable value.

Syntax

bool is_iterable ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The value to check

Return Values

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

Dependencies

PHP 7.1 and above

Example

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>";
?>

Output

This will produce following result −

a is bool(true)
b is bool(true)
c is bool(false)
d is bool(false)
php_variable_handling_functions.htm
Advertisements