is_scalar
Detect whether a variable is a scalar
is_scalar()
function checks whether the variable is a scalar.
If the variable is a scalar, this function returns true
(1), otherwise false
/ no return value.
An integer, floating point number, string, or boolean value can be a scalar variable. Arrays, objects, and resources are not the case.
Check if the variable is a scalar:
<?php $a = "Hello" ; echo "a is " . ( is_scalar ( $a ) ? 'scalar' : 'not scalar' ) . "<br>" ; $b = 0 ; echo "b is " . ( is_scalar ( $b ) ? 'scalar' : 'not scalar' ) . "<br>" ; $c = 32 ; echo "c is " . ( is_scalar ( $c ) ? 'scalar' : 'not scalar' ) . "<br>" ; $d = NULL ; echo "d is " . ( is_scalar ( $d ) ? 'scalar' : 'not scalar' ) . "<br>" ; $e = array ( "red" , "green" , "blue" ) ; echo "e is " . ( is_scalar ( $e ) ? 'scalar' : 'not scalar' ) . "<br>" ; ?>
Try it yourself
is_scalar ( variable ) ;
parameter | describe |
---|---|
variable | Required. Specifies the variable to check. |