PHP is_scalar() Function

PHP is_string() Function
PHP is_resource() Function

In this article, you will learn how to check if a variable is scalar or not in PHP. The PHP is_scalar() 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.

what is the syntax of the IS_SCALAR() function in php?

is_scalar(variable);
ParameterDescription
variableRequired. Specifies the variable to check
PHP IS_SCALAR() method

examples of the IS_SCALAR() function

Example 1. In this example, we 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>";
?>
PHP is_string() Function
PHP is_resource() Function
en English
X
Scroll to Top