• PHP Video Tutorials

PHP - is_scalar() Function


Advertisements

Definition and Usage

The function is_scalar() whether a variable is a scalar. Scalar variables are those containing an int, float, string or bool. Types array, object and resource are not scalar.

Syntax

bool is_scalar ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The variable being evaluated.

Return Values

This function returns true if value is a scalar, false otherwise. This function does not consider NULL to be scalar.

Dependencies

PHP 4.0.5 and above

Example

Following example demonstrates use of function is_scalar() −

<?php
   $a = "Tutorialspoint";
   echo "a is ".( is_scalar($a)? 'scalar' : 'not scalar') . "<br>";

   $b = 0;
   echo "b is ".( is_scalar($b)? 'scalar' : 'not scalar') . "<br>";

   $c = 40;
   echo "c is ".( is_scalar($c)? 'scalar' : 'not scalar') . "<br>";

   $d = NULL;
   echo "d is ".( is_scalar($d)? 'scalar' : 'not scalar') . "<br>";

   $e = array("a", "b", "c");
   echo "e is ".( is_scalar($e)? 'scalar' : 'not scalar') . "<br>";

   $f = 3.1416;
   echo "f is ".( is_scalar($f)? 'scalar' : 'not scalar') . "<br>";

   $g = new stdClass();
   echo "g is ".( is_scalar($g)? 'scalar' : 'not scalar') . "<br>";
?>

Output

This will produce following result −

a is scalar
b is scalar
c is scalar
d is not scalar
e is not scalar
f is scalar
g is not scalar
php_variable_handling_functions.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements