bool
is_scalar ( mixed
$var
)
If the given variable parameter var
is a scalar,is_scalar () returns TRUE
, otherwise returns FALSE
.
Scalar variables are variables that contain an integer,float,string, or Boolean, while array, object,and resource are not scalars.
<?php
functionShow_var($var) {
if (Is_scalar($var)) {
Echo$var;
} else {
Var_dump($var);
}
}
$pi=3.1416;
$proteins= Array ("Hemoglobin","Cytochrome c oxidase", ) ;
show_var $pi );
// print: 3.1416
show_var ( $proteins )
// Print:
// array (3) {
// [0]=>
// string " Hemoglobin "
// [1]=>
// string " cytochrome c Oxidase "
// [2]=>
// string " ferredoxin "
// }
Span style= "color: #0000bb;" >?>
Note:
Although the current resource types are in integers, is_scalar () does not treat them as scalars, because resources are abstract data types. The execution details cannot be relied upon, as it may change.
See Is_bool (),is_numeric (),is_float (),is_int (),is_real (),is_string (),is_object (), Is_array () and Is_integer ().
is_scalar-Check if the variable is a scalar (PHP 4 >= 4.0.5, PHP 5, PHP 7)