In-depth understanding of the relationship between 0, null, empty, null, false, and strings in php
// Judge the relationship between 0 and ''and empty null false. start //
If ('safdasefasefasf' = 0 ){
- Echo "this string is converted to a number equal to 0
";
- } // Output: the string is converted to a value equal to zero.
This is a key example.
This value is determined by the first part of the string. If a string starts with a valid number, use this number as its value. Otherwise, its value is 0 (0 ).
That is to say, '3asfdf '= 3; 'adsfasdf' = 0.
$ A = 0;
- If ($ a = ''){
- Echo "0 equals''
";
- } // Output: 0 equals''
- If (trim ($ a) = ''){
- Echo "trim (0) equals''
";
- } // No output
If ($ a = ''){
- Echo "0 =''
";
- } // No output
- If (empty ($ )){
- Echo "'' is empty
";
- } // Output: ''is empty
- If (is_null ($ )){
- Echo "0 is null
";
- } // No output
- If (is_numeric ($ )){
- Echo "0 is numeric
";
- } // Output: 0 is numeric
- If (is_string ($ )){
- Echo "0 is string
";
- } // No output
- If (strval ($ a) = ''){
- Echo "convert to string 0 is''
";
- } // No output
- // Determine the relationship between 0 and ''and empty null false. end //
// Judge the relationship between ''and 0 and empty null false. start //
$ B = '';
- If ($ B = 0 ){
- Echo "'' equals 0
";
- } // Output: ''equals 0
- If (! ''){
- Echo "'' is false.
";
- } // Output: ''is false.
- If (! 0 ){
- Echo "0 is false
";
- } // Output: 0 is false bbs.it-home.org
- // Determine the relationship between ''and 0 and empty null false. end //
Echo "when judging null (''), be careful. 0 is equivalent to '', 0 and'', both are equivalent to null and false, it is best to use = ";
- ?>
Output result: 0 is equal to "" is empty 0 is numeric "is equal to 0". false 0 is false. be careful when determining null ("). 0 is equivalent ", both 0 and "are equivalent to null characters and false. it is best to use = to judge as null. it can only be interpreted as follows: 0 is also equivalent to", 0 and "are equivalent to null characters and false. Be careful when determining the null ("). 0 is equivalent to", 0 and "are equivalent to null characters and false. it is best to use = to judge the null; Echo 0 = null; echo '** '; // Trueecho 0 === null; echo '** '; // Falseecho (string) 0! = Null; echo '** '; // Trueecho 0! = Null; echo '** '; // Falseecho 0! = Null; echo '** '; // True |