PHP Basics: Variable Detection

Source: Internet
Author: User
Tags php basics

$a =null;
Var_dump ($a);

$b = 2;
Var_dump ($b);
Var_dump (Isset ($c));//isset detects if a variable exists but when detecting it, be aware that NULL is also returned as false.

There are many types of detection variables you can use GetType to detect what type of variable it is, but it is not recommended to use slow and useful is_** to detect whether a variable is a specified type
$a =null;
Echo GetType ($a);//return NULL

$a = 12;
Var_dump (Ia_int ($a));//return bool


Topic
$b = "I am a string";
if (is_string ($b)) {
echo "I'm a string"
}else{
Echo ' NO ';
}

$b = 222;
if (is_string ($b)) {
Echo ' I am a string ';
}else{
Echo ' I'm not a string ';
}

Conversion math operators for string-to-integer
$a = 5;
$b = "6hello";
$c = $a + $b;
Var_dump ($c); returns INT (11)

Numeric to string conversion concatenation operator
$a = 6;
$b = ' Hello World ';
$c = $a. $b;
Var_dump ($c)//return string (6hello world);

Conversion comparison operator for numeric array strings to Boolean values
An empty string of 0 0.0 null array () False returns a Boolean value of False

Detects if the variable is empty
$a = 23;
Var_dump (Empty ($a));//Returns a Boolean of false, NULL returns a Boolean value of True NOT NULL returns false

PHP Basics: Variable Detection

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.