is_countable
Verify that the content of the variable is a countable value
The is_countable()
function is used to check whether the content of a variable is a countable value.
If the variable is countable, the function returns true
(1), otherwise false
/ no content.
Check whether the content of a variable is a countable value:
<?php $a = "Hello" ; echo "a is " . is_countable ( $a ) . "<br>" ; $b = array ( "red" , "green" , "blue" ) ; echo "b is " . is_countable ( $b ) . "<br>" ; $c = array ( "Peter" => "35" , "Ben" => "37" , "Joe" => "43" ) ; echo "c is " . is_countable ( $c ) . "<br>" ; $d = [ 1 , 2 , 3 ] ; echo "d is " . is_countable ( $d ) . "<br>" ; ?>
Try it yourself
The variable $a
contains a string, which is not a countable value, so is_countable($a)
will return FALSE
. The variables $b
, $c
and $d
contain arrays, which are countable values, so is_countable($b)
, is_countable($c)
and is_countable($d)
will all return TRUE
. Arrays are countable, whether they are index arrays or associative arrays.
is_countable ( variable ) ;
parameter | describe |
---|---|
variable | Required. Specifies the variable to check. |