Sometimes we want to output the variables in the characters we may use Dump_var but if we want to output automatically, we need to liquidated the function.
|
copy code |
"!--? php function show_var ($var) { Br>if (Is_scalar ($var)) { echo $var; } else { Var_dump ($var); } } $pi = 3.1416; $proteins = Array ("Hemoglobin", "cytochrome c oxidase", "ferredoxin"); Show_var ($PI); //print: 3.1416 Show_var ($proteins) //print: //Array (3) { //[0]=> //String (Ten) "hemoglobin" //[1]=> // String "Cytochrome c oxidase" //[2]=> //String (Ten) "ferredoxin" //} ? |
Describe
BOOL Is_scalar (mixed $var)
If the given variable parameter var is a scalar, is_scalar () returns TRUE, otherwise FALSE is returned.
Scalar variables are variables that contain an integer, float, String, or Boolean, while array, object, and resource are not scalars.
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.
http://www.bkjia.com/PHPjc/629106.html www.bkjia.com true http://www.bkjia.com/PHPjc/629106.html techarticle sometimes we want to output the variables in the characters we may use Dump_var but if we want to output automatically, we need to liquidated the function. Code to copy code like this? PHP function Show_v ...