Home > Article > Backend Development > What is the calculation formula for addition, subtraction, multiplication and division in php
In PHP, you can use arithmetic operators to implement calculation formulas for addition, subtraction, multiplication and division. Arithmetic operators are used to operate on the values on both sides of the symbol. The calculation formulas are "x y", "x - y", "x * y" and "x / y" respectively represent the sum, difference, product and quotient of two numbers.
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
PHP Arithmetic operators are similar to operators in mathematics, both have addition, subtraction, multiplication and division.
The most basic arithmetic operators
Add
Subtract -
Multiple *
Division/
Get The remaining %
examples are as follows:
<?php $x = 100; $y = 150; echo ($x + $y)."<br>"; // 输出 250 echo ($x - $y)."<br>"; // 输出 -100 echo ($x * $y)."<br>"; // 输出 1500 echo ($x / $y)."<br>"; // 输出 0.6666666666667 echo ($x % $y); // 输出 1 ?>
Output results:
Recommended learning: "PHP Video tutorial》
The above is the detailed content of What is the calculation formula for addition, subtraction, multiplication and division in php. For more information, please follow other related articles on the PHP Chinese website!