PHP | is_countable() Function

The is_countable() function is an inbuilt function in PHP which is used to check whether the content of the variable is countable or not.

Syntax:

bool is_countable ( mixed $var )

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

  • $var: This parameter holds the value which need to be checked.

Return Value: This function returns a boolean value i.e. either True if value of variable is countable otherwise returns False.

Below programs illustrate the is_countable() function in PHP:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declare a string
$str = "GeeksforGeeks"
  
var_dump(is_countable($str));
  
$arr = array(1, 3, 5, 7);
  
var_dump(is_countable($arr));
?> 

chevron_right


Output:

bool(false) 
bool(true) 

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declare a number
$num = 1234;
var_dump(is_countable($num));
  
// Declare an array
$arr = array('Welcome', 'to', 'GeeksforGeeks');
var_dump(is_countable($arr));
  
// Declare a string
$str = "GeeksforGeeks"
var_dump(is_countable($str));
  
// Declare an empty class
class GFG {
    // Empty class
}
  
// Create an object of class
$obj = new GFG();
var_dump(is_countable($obj));
  
// Create an array iterator object
$itr = new ArrayIterator();
var_dump(is_countable($itr));
?> 

chevron_right


Output:

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

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.