PHP is_scalar() function
is_scalar()The function is used to detect whether a variable is a scalar.
Scalar variables are those that contain integer, float, string, or boolean, while array, object, and resource are not scalar.
PHP 4 >= 4.0.5, PHP 5, PHP 7
Syntax
bool is_scalar ( mixed $var )
Parameter description:
- $var: The variable to be detected.
Return Value
Returns TRUE if the specified variable is scalar, otherwise returns FALSE.
Example
Example
function show_var($var) {
if (is_scalar($var)) {
echo $var;
} else {
var_dump($var);
}
}
$pi = 3.1416;
$sites = array("Example", "Google", "Facebook");
show_var($pi);
echo PHP_EOL;
show_var($sites)
Output result:
3.1416
array(3) {
[0]=>
string(6) "Example"
[1]=>
string(6) "Google"
[2]=>
string(8) "Facebook"
}
Other extensions
PHP available functions