Home >Backend Development >PHP Tutorial >The difference between null, 0, and false in php updatedata false javascript:false async fals
The
empty() function is used to determine whether a string is empty.
As long as the variable is 0, null, '', false, empty() will be judged to be true.
$num1=''; $num2=0; echo $num1==$num2; echo '<br/>'; echo $num1===$num2 ? '1' : '0';
The reason is that variables in PHP are stored in C language structures. Empty strings, NULL, and false are all stored with a value of 0, and this structure There is a member variable like zend_uchartype;, which is used to save the type of the variable. The type of empty string is string, the type of NULL is NULL, and false is boolean. The === operator not only compares values, but also types.
Judge the empty string and 0 like this:
$num1=''; $num2=0; if(empty($num1) && $num1===''){ echo "true"; } if(empty($num2) && $num2===0){ echo 'true'; }The result is:
The above introduces the differences between null, 0, and false in PHP, including the content of false and null. I hope it will be helpful to friends who are interested in PHP tutorials.