Some tips on PHP programming

Source: Internet
Author: User

1. Distinction between null,0 and voidness

(1) The distinction between 0 and NULL

<?php $a = 0;if ($a = = ") {echo ' This judgment condition cannot be distinguished ';} else{Echo ' This judging condition can be differentiated ';}?>

<?php $a = 0;if ($a = = = ") {echo ' This judging condition cannot be distinguished ';} else{Echo ' This judging condition can be differentiated ';}?>

<?php $a = 0; $b = ", if (empty ($a) && empty ($b)) {echo ' This judgment condition cannot be distinguished ';} else{Echo ' This judging condition can be differentiated ';}? >

<?php $a = 0; $b = ", if (!is_null ($a)) && (!is_null ($b))) {echo ' This judgment condition cannot be distinguished ';} Else{echo ' This judging condition can be differentiated ';}?>

<?php $a = 0; $b = ", if (isset ($a) && isset ($b)) {echo ' This judgment condition cannot be distinguished ';} Else{echo ' This judging condition can be differentiated ';}?>

Conclusion: 0 and NULL can only be used to determine the difference between = = =.

(2) The distinction between null and void

<?php $a = ", if ($a ==null) {echo ' This judging condition cannot be distinguished ';} Else{echo ' This judging condition can be differentiated ';}?>

<?php $a = ", if ($a ===null) {echo ' This judging condition cannot be distinguished ';} Else{echo ' This judgment condition can be differentiated ';} ?>

<?php $a = '; $b = null;if (Empty ($a) && empty ($b)) {echo ' This judgment condition cannot be distinguished ';} Else{echo ' This judgment condition can be differentiated ';}? >

<?php $a = "; $b = Null;if (Is_null ($a)) {echo 1;} Else{echo 2;} if (Is_null ($b)) {echo ' <br/>a ';} Else{echo ' B ';}?>

<?php $a = "; $b = Null;if (isset ($a)) {echo 1;} Else{echo 2;} if (Isset ($b)) {echo ' <br/>a ';} Else{echo ' <br/>b ';}?>

Conclusion: The distinction between null and void can use ===,is_null,isset.

(3) distinction between 0 and NULL

<?php $a = 0;if ($a ==null) {echo ' This judging condition cannot be distinguished ';} Else{echo ' This judgment condition can be differentiated ';}? >

<?php $a = 0;if ($a ===null) {echo ' This judging condition cannot be distinguished ';} Else{echo ' This judgment condition can be differentiated ';}? >

<?php $a = 0; $b = null;if (Empty ($a) && empty ($b)) {echo ' This judgment condition cannot be distinguished ';} Else{echo ' This judgment condition can be differentiated ';}? >

<?php $a = 0; $b = null;if (Is_null ($a)) {echo 1;} Else{echo 2;} if (Is_null ($b)) {echo ' <br/>a ';} Else{echo ' <br/>b ';}? >

<?php $a = 0; $b = null;if (isset ($a)) {echo 1;} Else{echo 2;} if (Isset ($b)) {echo ' <br/>a ';} Else{echo ' <br/>b ';}? >

Conclusion: The distinction between 0 and null can be used ===,is_null,isset.

In summary, we distinguish 0, null and NULL when the preferred = = = Method, simple and practical fast. No factor group conversions cause errors in data type changes.

Some tips on PHP programming

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.