PHP 比较运算符实例

PHP 比较运算符实例

尝试以下示例以了解所有比较运算符。将以下PHP程序复制并粘贴到test.php文件中,将其保存在您的PHP服务器的文档根目录中,并使用任何浏览器进行浏览。

<html>

   <head>
      <title>Comparison Operators</title>
   </head>

   <body>

      <?php
         a = 42;b = 20;

         if( a ==b ) {
            echo "TEST1 : a is equal to b<br/>";
         }else {
            echo "TEST1 : a is not equal to b<br/>";
         }

         if( a>b ) {
            echo "TEST2 : a is greater than  b<br/>";
         }else {
            echo "TEST2 : a is not greater than b<br/>";
         }

         if( a<b ) {
            echo "TEST3 : a is less than  b<br/>";
         }else {
            echo "TEST3 : a is not less than b<br/>";
         }

         if( a !=b ) {
            echo "TEST4 : a is not equal to b<br/>";
         }else {
            echo "TEST4 : a is equal to b<br/>";
         }

         if( a >=b ) {
            echo "TEST5 : a is either greater than or equal to b<br/>";
         }else {
            echo "TEST5 : a is neither greater than nor equal to b<br/>";
         }

         if( a <=b ) {
            echo "TEST6 : a is either less than or equal to b<br/>";
         }else {
            echo "TEST6 : a is neither less than nor equal to b<br/>";
         }
      ?>

   </body>
</html>

这将产生以下结果−

TEST1 : a is not equal to b
TEST2 : a is greater than b
TEST3 : a is not less than b
TEST4 : a is not equal to b
TEST5 : a is either greater than or equal to b
TEST6 : a is neither less than nor equal to b

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程