is_scalar()
is_scalar() — Finds whether a variable is a scalar.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Finds whether an expression is evaluated as a scalar value.
Signature
is_scalar(mixed $value): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $value | mixed | The variable being evaluated. |
Return value
Returns true if value is a scalar, false otherwise.
Example
A runnable snippet:
function show_var($var) { if (is_scalar($var)) { echo $var, PHP_EOL; } else { var_dump($var); } } $pi = 3.1416; $proteins = array("hemoglobin", "cytochrome c oxidase", "ferredoxin"); show_var($pi); show_var($proteins)
Output:
3.1416 array(3) { [0]=> string(10) "hemoglobin" [1]=> string(20) "cytochrome c oxidase" [2]=> string(10) "ferredoxin" }
See also
is_float(), is_int(), is_numeric(), is_string(), is_bool(), is_object(), is_array()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page is_scalar() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.