Created
June 14, 2018 15:56
-
-
Save Erenor/5dd088290709ce754166589df0cceac1 to your computer and use it in GitHub Desktop.
[PHP] The comparison with two equal signs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//to be used when you are not really sure about the outcome of a comparison, or when you get an "unexpected" result | |
$a = array( 'a', 0, '0', false, null, ); | |
$b = $a; | |
foreach($a as $temp) { | |
foreach($b as $meow) { | |
echo var_export($temp, true) . ' == ' . var_export($meow, true) . ' : ' . var_export($temp == $meow, true); | |
echo '<br>'; | |
} | |
} | |
//output | |
//'a' == 'a' : true | |
//'a' == 0 : true | |
//'a' == '0' : false | |
//'a' == false : false | |
//'a' == NULL : false | |
//0 == 'a' : true | |
//0 == 0 : true | |
//0 == '0' : true | |
//0 == false : true | |
//0 == NULL : true | |
//'0' == 'a' : false | |
//'0' == 0 : true | |
//'0' == '0' : true | |
//'0' == false : true | |
//'0' == NULL : false | |
//false == 'a' : false | |
//false == 0 : true | |
//false == '0' : true | |
//false == false : true | |
//false == NULL : true | |
//NULL == 'a' : false | |
//NULL == 0 : true | |
//NULL == '0' : false | |
//NULL == false : true | |
//NULL == NULL : true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment