PHP - 算术运算符示例


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

<html>
   
   <head>
      <title>Arithmetical Operators</title>
   </head>
   
   <body>
   
      <?php
         $a = 42;
         $b = 20;
         
         $c = $a + $b;
         echo "Addtion Operation Result: $c <br/>";
         
         $c = $a - $b;
         echo "Substraction Operation Result: $c <br/>";
         
         $c = $a * $b;
         echo "Multiplication Operation Result: $c <br/>";
         
         $c = $a / $b;
         echo "Division Operation Result: $c <br/>";
         
         $c = $a % $b;
         echo "Modulus Operation Result: $c <br/>";
         
         $c = $a++; 
         echo "Increment Operation Result: $c <br/>";
         
         $c = $a--; 
         echo "Decrement Operation Result: $c <br/>";
      ?>
   
   </body>
</html>

这将产生以下结果 -

Addtion Operation Result: 62 
Substraction Operation Result: 22 
Multiplication Operation Result: 840 
Division Operation Result: 2.1 
Modulus Operation Result: 2 
Increment Operation Result: 42 
Decrement Operation Result: 43 
php_operator_types.htm