Current Location: Home> Function Categories> is_scalar

is_scalar

Detect whether a variable is a scalar
Name:is_scalar
Category:Variable processing
Programming Language:php
One-line Description:Check whether the variable is a scalar.

Definition and usage

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.

Example

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

grammar

 is_scalar ( variable ) ;
parameter describe
variable Required. Specifies the variable to check.
Similar Functions
Popular Articles