PHP | is_countable() Function
Last Updated :
21 Apr, 2020
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:
<?php
$str = "GeeksforGeeks" ;
var_dump(is_countable( $str ));
$arr = array (1, 3, 5, 7);
var_dump(is_countable( $arr ));
?>
|
Output:
bool(false)
bool(true)
Program 2:
<?php
$num = 1234;
var_dump(is_countable( $num ));
$arr = array ( 'Welcome' , 'to' , 'GeeksforGeeks' );
var_dump(is_countable( $arr ));
$str = "GeeksforGeeks" ;
var_dump(is_countable( $str ));
class GFG {
}
$obj = new GFG();
var_dump(is_countable( $obj ));
$itr = new ArrayIterator();
var_dump(is_countable( $itr ));
?>
|
Output:
bool(false)
bool(true)
bool(false)
bool(false)
bool(true)
Reference: https://www.php.net/manual/en/function.is-countable.php
Share your thoughts in the comments
Please Login to comment...