哪个是正确的语法不等于operator
这 - > !=
if($ses_startdate != $startdate) {
echo "I am true";
}
或者这个 - > !==
if($ses_startdate !== $startdate) {
echo "I am true";
}
我一直在使用!= =之前它没有任何问题,但不是它创造了一些条件的问题,当我把它改为!=它工作正常..为什么会这样?
答案 0 :(得分:7)
!==
比!=
更严格,!==
也检查数据类型。
例子:
$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;
答案 1 :(得分:1)
$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).
所以,第三个=
告诉php检查类型。
答案 2 :(得分:1)
$ses_startdate != $startdate
在进行任何分析你的代码的比较时,习惯做相当于
的事情 var_dump ( $ses_startdate );
var_dump ( $startdate );
在该条件之前,将值转储到页面上或将其放入error_logs中,这样您就可以看到PHP正在评估变量的类型和值。