代码之家  ›  专栏  ›  技术社区  ›  Ibrahim Azhar Armar

这个比较运算符的正确语法是什么

php
  •  1
  • Ibrahim Azhar Armar  · 技术社区  · 15 年前

    is not equal to运算符的正确语法是什么

    if($ses_startdate != $startdate) {
                    echo "I am true";
                }
    

    或者这个->!==

    if($ses_startdate !== $startdate) {
                    echo "I am true";
                }
    

    我一直在用!==以前,它工作没有任何问题,但不是它创造了一些条件的问题,当我把它改为!=工作正常。。为什么?

    3 回复  |  直到 15 年前
        1
  •  7
  •   Lekensteyn    15 年前

    !== != , !== 还要检查数据类型。 示例:

    $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;
    
        2
  •  1
  •   Hugo Mota    15 年前
    $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).
    

    所以,第三个 =

        3
  •  1
  •   Cups    15 年前

    $ses_startdate != $startdate

    当你做任何代码分叉的比较时,要习惯于做

    var_dump ( $ses_startdate );

    var_dump ( $startdate );

    推荐文章