PHP - 赋值运算符示例


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

<html>
   
   <head>
      <title>Assignment Operators</title>
   </head>
   
   <body>
      
      <?php
         $a = 42;
         $b = 20;
         
         $c = $a + $b;  
         echo "Addtion Operation Result: $c <br/>";
         
         $c += $a;  
         echo "Add AND Assigment Operation Result: $c <br/>";
         
         $c -= $a;
         echo "Subtract AND Assignment Operation Result: $c <br/>";
         
         $c *= $a; 
         echo "Multiply AND Assignment Operation Result: $c <br/>";
         
         $c /= $a; 
         echo "Division AND Assignment Operation Result: $c <br/>";
         
         $c %= $a;
         echo "Modulus AND Assignment Operation Result: $c <br/>";
      ?>
      
   </body>
</html>

这将产生以下结果 -

Addtion Operation Result: 62 
Add AND Assigment Operation Result: 104 
Subtract AND Assignment Operation Result: 62 
Multiply AND Assignment Operation Result: 2604 
Division AND Assignment Operation Result: 62 
Modulus AND Assignment Operation Result: 20 
php_operator_types.htm