PHP is_scalar() Function
Last Updated :
04 Apr, 2023
PHP_scalar() function is an inbuilt function in PHP and is used to check whether a variable is a scalar or not.
Syntax:
bool is_scalar ( $var )
Parameter: This function accepts a single parameter as shown in the above syntax and described below.
- $var: Variable to check if it is a scalar or not.
Return Value: It returns TRUE when $var is scalar, otherwise it returns FALSE.
Note:
- Variables which contain boolean, double, integer or string types are scalar.
- Array, object, and resource are not scalar.
- is_scalar() does not consider NULL to be scalar.
Below program illustrate the is_scalar() function in PHP:
Example:
php
<?php
$var1 = true;
var_dump( is_scalar ( $var1 ));
$var2 = 3;
var_dump( is_scalar ( $var2 ));
$var3 = 5.6;
var_dump( is_scalar ( $var3 ));
$var4 = "Abc3462";
var_dump( is_scalar ( $var4 ));
$var5 = array (1, 2, 3);
var_dump( is_scalar ( $var5 ));
$var6 = new stdClass;
var_dump( is_scalar ( $var6 ));
$var7 = tmpfile();
var_dump( is_scalar ( $var7 ));
?>
|
Output:
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)
Reference: http://php.net/manual/en/function.is-scalar.php
Share your thoughts in the comments
Please Login to comment...