PHP 中 !== 和 ==! 運算子的區別


'!==' 比較運算子

'!==' 運算子檢查兩個物件的型別是否相等。它不轉換資料型別,而是執行型別檢查。例如,1 !== '1' 會返回 true。

'==!' 比較運算子

'==!' 運算子是兩個運算子的組合,可以寫成 == (!運算物件)。

示例

下面的示例展示了 '!=='' 和 '==!' 運算子的用法。

 即時演示

<!DOCTYPE html>
<html>
<head>
   <title>PHP Example</title>
</head>
<body>
   <?php
      $x = true;
      $y = false;
      echo '$x !== operator $y = ';

      // $x not equals to $y
      // so true returned
      var_dump($x !== $y);
      print("<br/>");
      echo '$x ==! operator $y = ';
      // !$y is true which is same as $x
      // so true returned
      var_dump($x ==! $y);
   ?>
</body>
</html>

輸出

$x !== operator $y = bool(true)
$x ==! operator $y = bool(true)

更新時間: 13-1 月-2020

470 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

開始學習
廣告