Thursday, October 23, 2025
HomeLanguagesPHP | is_iterable() Function

PHP | is_iterable() Function

The is_iterable() function is an inbuilt function in PHP which is used to check whether the contents of a variable is an iterable value or not.

Syntax:

bool is_iterable( mixed $var )

Parameters: This function accepts single parameter as mentioned above and described below:

  • $var: It contains the value of variable that need to be check.

Return Value: It returns TRUE if the value of variable is iterable, FALSE otherwise.

Program 1:




<?php
  
// Declare an array
$arr = array(1, 2, 3, 4, 5);
  
if(is_iterable($arr)) {
    echo "Array is iterable";
}
else {
    echo "Array is not iterable";
}
  
// Create a class
class GFG {
}
   
// Create an object
$obj = new GFG();
  
if(is_iterable($obj)) {
    echo "\nObject is iterable";
}
else {
    echo "\nObject is not iterable";
}
?>


Output:

Array is iterable
Object is not iterable

Program 2:




<?php
  
// Create a class
class GFG {
    public $Geek_name = "Welcome to neveropen"; 
}
  
$obj = new GFG();
var_dump(is_iterable($obj));
  
$arr = array('G', 'e', 'e', 'k', 's');
var_dump(is_iterable($arr));
  
$num = 25;
var_dump(is_iterable($num));
  
$str = "neveropen";
var_dump(is_iterable($str));
  
$bool = true;
var_dump(is_iterable($bool));
?>


Output:

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

Reference: https://www.php.net/manual/en/function.is-iterable.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS