Easy Tutorial
❮ Php Coalescing Operator Pdo Getattribute ❯

PHP is_scalar() Function

PHP Available Functions

The is_scalar() function is used to check if a variable is a scalar.

A scalar variable is one that contains an integer, float, string, or boolean, whereas arrays, objects, and resources are not scalar.

PHP 4 >= 4.0.5, PHP 5, PHP 7

Syntax

bool is_scalar ( mixed $var )

Parameter Description:

Return Value

Returns TRUE if the specified variable is scalar, otherwise returns FALSE.

Example

<?php
function show_var($var) {
    if (is_scalar($var)) {
        echo $var;
    } else {
        var_dump($var);
    }
}
$pi = 3.1416;
$sites = array("tutorialpro", "Google", "Facebook");

show_var($pi);
echo PHP_EOL;
show_var($sites)
?>

Output:

3.1416
array(3) {
  [0]=>
  string(6) "tutorialpro"
  [1]=>
  string(6) "Google"
  [2]=>
  string(8) "Facebook"
}

PHP Available Functions

❮ Php Coalescing Operator Pdo Getattribute ❯