-
-
//Judge the relationship between 0 and '' and empty null false start//
if('safdasefasefasf'==0) {
- echo "The string is converted into a number equal to 0
";
- }//output: The string is converted into a number equal to zero.
This is a key example
The manual explains: The value is determined by the first part of the string. If the string begins with legal numeric data, that number is used as its value, otherwise its value is 0 (zero).
In other words, '3asfdf'==3 ; 'adsfasdf'==0 Be very careful
$a=0;
- if($a= =''){
- echo "0 is equal to ''
";
- } //output:0 is equal to ''
- if(trim($a)==''){
- echo "trim(0 ) is equal to ''
";
- } //no output
if($a===''){
- echo "0===''
";
- } //no output
- if(empty($a)){
- echo "'' is empty
";
- } //output:'' is empty
- if(is_null ($a)){
- echo "0 is null
";
- } //no output
- if(is_numeric($a)){
- echo "0 is numeric
";
- } //output:0 is numeric
- if(is_string($a)){
- echo "0 is string
";
- } //no output
- if(strval($a)==' '){
- echo "0 converted into a string is ''
";
- } //no output
- // Determine the relationship between 0 and '' and empty null false end //
// Determine the relationship between '' and 0 and empty null false start //
$b = '';
- if($b==0){
- echo "'' is equal to 0
";
- } //output:'' is equal to 0
- if(!''){
- echo "'' is false
";
- } // output:'' is false
- if(!0){
- echo "0 is false
";
- } //output:0 is false bbs.it-home.org
- // Judge '' and The relationship between 0 and empty null falseend //
echo "Be careful when judging empty (''), 0 is also equivalent to '', 0 and '' are both equivalent to empty Characters and false, it is best to use ===";
- ?>
-
Copy the code
Output results:
0 is equal to " " is empty 0 is numeric " is equal to 0 " which is false. 0 is false. Be careful when judging empty ("). 0 is also equivalent to ". 0 and " are both equivalent to empty characters and false, and are judged to be empty. It is best to use === and can only be explained this way: 0 is also equivalent to ", 0 and " are equivalent to the null character and false.
Be careful when judging empty ("). 0 is also equivalent to ", 0 and " are equivalent to empty characters and false. It is best to use === when judging empty;
echo 0 == null; echo '** ' ; //true
echo 0 === null; echo '** ' ; //false
echo (string)0 != null; echo '** ' ; //true
echo 0 != null; echo '** ' ; //false
echo 0 !== null; echo '** ' ; //true |