Which is the correct syntax for is not equal to operator
this -> !=
if($ses_startdate != $startdate) {
echo "I am true";
}
or this -> !==
if($ses_startdate !== $startdate) {
echo "I am true";
开发者_开发问答 }
I had been using !== earlier and it worked without any problem but not it is creating the problem with some condition and when i changed it to != it works fine.. why is that?
!==
is more strict than !=
, !==
also check the datatype.
Examples:
$a = 1;
$b = '1';
$c = 1;
$d = TRUE;
// These are true:
$a == $c;
$a == $b;
$a === $c
$a == $d;
// but these are FALSE:
$a === $b;
$a === $d;
$a = '';
$b = false;
if($a != $b)
//it is not executed since $a and $b are the same (empty) but have different types.
if($a !== $b)
//it is executed, because $a is a string and $b is boolean, even though both of them represent the same value (empty).
so, the third =
tells php to check for the type too.
$ses_startdate != $startdate
When doing any comparison which forks your code, get used to doing the equivalent of
var_dump ( $ses_startdate );
var_dump ( $startdate );
Just prior to that condition, dump the values onto the page or put it into your error_logs so you can see what PHP is assessing variables' types and values.
精彩评论