= 7.10 Syntax bool is_iterable ( mixed $var ) Parameter Description: $var: The variable to be checked" />



English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP is_iterable() Function Usage and Example

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, which can be an array or an object that implements the Traversable interface.

Return Value

If the specified variable is an iterable object, it returns TRUE; otherwise, it returns FALSE.

Online 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 Available Functions