PHP is scalar

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : is_scalar() function

Description

The is_scalar() function is used to check whether a variable is a scalar or set or not.
Note : Variables which contain boolean, double, integer, or string types are scalar. Array, object, and resource are not scalar.

Version

(PHP 4 and above)

Syntax

is_scalar(variable_name) 

Parameter

Name

Description

Required /
Optional

Type

variable_name

The variable being checked

Required

Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value

TRUE if variable_name is a scalar, FALSE otherwise.

Value Type : Boolean

Example :

  1. $var1 = 100;  

  2. if (is_scalar ($var1))  

  3. echo $var1. ' is a scalar value'.'
    ';  

  4. else  

  5. echo $var1.' is not a  scalar value'.'
    ';  

  6. $var2 = array(1);  

  7. if (is_scalar ($var2))  

  8. echo $var2. ' is a scalar value'.'
    ';  

  9. else  

  10. echo  $var2. ' is not a  scalar value'.'
    ';  

  11. ?>  

Output :

100 is a scalar value
Array is not a scalar value