(basic) The difference between PHP 0 and null null FALSE

Source: Internet
Author: User
Tags null null

<?PHP$test=0;if($test= = "'){ Echo' <br/> In php, 0 is empty ';//is output}if($test= = = ""){ Echo' <br/> In php, 0 is empty ';//not be output}if($test==NULL){ Echo' <br/> In php, 0 is empty ';//is output}if($test===NULL){ Echo' <br/> In php, 0 is empty ';//not be output}if($test==false){ Echo' <br/> In php, 0 is empty ';//is output}if($test===false){ Echo' <br/> In php, 0 is empty ';//not be output}?>

The reason is that in PHP the variables are stored in the C language structure, and the empty string and null,false are stored with a value of 0, where the struct has a zend_uchar type, a member variable that is used to hold the type of the variable, and the type of the empty string is string, The type of NULL is Null,false is Boolean.

This can be used with echo GetType ("); and Echo GetType (NULL); the = = = operator is not only the comparison value, but also the comparison type, so the third one is false!

So it can be said that = = = is equal to the following function:

function eq ($v 1$v 2) {if($v 1$v 2GetType( $v 1 GetType ($v 2)) {return 1else  {return 0;}}

So the empty string ('), False,null and 0 are values equal and the type is different!

Attention:

Null is a special type.

Null in both cases

1. $var = NULL;

2. $var;

3. "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty and return TRUE if Var is empty.

Summarize

From the above example we can see that Null,0,false is false, and that ' is an empty string is not a null value.

(Basic) The difference between PHP 0 and null null false

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.