Skip to content

Instantly share code, notes, and snippets.

@Erenor
Created June 14, 2018 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erenor/5dd088290709ce754166589df0cceac1 to your computer and use it in GitHub Desktop.
Save Erenor/5dd088290709ce754166589df0cceac1 to your computer and use it in GitHub Desktop.
[PHP] The comparison with two equal signs
//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