Differences between null0empty & quot; in php

Source: Internet
Author: User
Many people have not considered the relationship between string () and NULL !! Now let me explain: Let's first look at an example: NULL; after running, we will find that the first is true, and the second is false! Why? In fact, both PHP hollow strings and NULL are stored as 0! And only compare, so

Many people have not considered the relationship between the string ('') and NULL !! Now let me explain: Let's first look at an example: ''= NULL; after running, we will find that the first is true, and the second is false! Why? In fact, both PHP hollow strings and NULL are stored as 0! And = only compare, so

Many people have not considered the relationship between the string ('') and NULL !!
Now let me explain:
Let's take a look at an example:
''= NULL;
''= NULL;
After running the command, the first value is true, and the second value is false!


Why?
In fact, both PHP hollow strings and NULL are stored as 0 values!

And = only compare the value, so the first is true! But why is the second option false !?
The reason is that the variables in PHP are stored in the C-language structure, where the structure has a zend_uchar type. Such a member variable is used to save the type of the variable, the empty string type is string, and the NULL type is NULL.

Echo gettype (''); and echo gettype (NULL); can be used to print this point! The ===operator is not only a comparison value, but also a comparison type. Therefore, the second operator is false!
So it can be said that = is equal to the following function:

 function eq($var1, $var2) {         if($var1 == $var2 && gettype($var1) == gettype($var2)) {                 return 1;         } else {                 return 0;         }}

So the NULL String (''), NULL and 0 are of the same value and different types!
Note:
NULL is a special type.
NULL in both cases
1. $ var = NULL;

2. $ var;

Summary:

Both string and NULL are stored as 0 values, so null = 0 = ''.

Null = 0 null = empty (true)

Null = 0 null = empty (not valid)

All of the following outputs are available:

if(0==null){echo "0null";echo "
";}if(null==''){ echo "nullkong";echo "
";}if(null !== 0){echo "abs null0";echo "
";}if('' == 0){echo "empty0";}

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.