PHP automatically identifies the Echo or dump_php tutorial based on the type of variable

Source: Internet
Author: User
Tags scalar
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.