PHP is_scalar() Function
❮ PHP Variable Handling Reference
Example
Check whether a variable is a scalar or not:
<?php
$a = "Hello";
echo "a is " . is_scalar($a) . "<br>";
$b = 0;
echo "b is
" . is_scalar($b) . "<br>";
$c = 32;
echo "c is " . is_scalar($c) .
"<br>";
$d = NULL;
echo "d is " . is_scalar($d) . "<br>";
$e = array("red", "green", "blue");
echo "e is " . is_scalar($e) . "<br>";
?>
Try it Yourself »
Definition and Usage
The is_string() function checks whether a variable is a scalar or not.
This function returns true (1) if the variable is a scalar, otherwise it returns false/nothing.
Integers, floats, strings, or boolean can be scalar variables. Arrays, objects, and resources are not.
Syntax
is_scalar(variable);
Parameter Values
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check |
Technical Details
Return Value: | TRUE if variable is a scalar, FALSE otherwise |
---|---|
Return Type: | Boolean |
PHP Version: | 4.0.5+ |
❮ PHP Variable Handling Reference