Arithmetic operators for PHP
Follow @ggarronPHP arithmetic operators
Today we will lear about aritmetic operators for PHP.
These are the arithmetic operators, below also a simple example, using the sum operator, to perform a simple sum of three numbers.
| Operation | Example | Result |
| Sum | $a + $b | The sum of a and b |
| Substraction | $a - $b | Difference of a and b |
| Multiplication | $a * $b | Product of a and b |
| Division | $a / $b | Quotient of a and b |
| Modulus | $a % $b | Remainder |
Examples of Arithmetic operators
Let's see a little example of some PHP coding to use some of these operators.
<html> <head> <title>Arithmetic Operators for PHP</title> </head> <Body> <form name="form1" method="post" action "example.php"> sum1 <input name="sum1" type="text"><br> sum2 <input name="sum2" type="text"><br> sum3 <input name="sum3" type="text"><br> <input type="submit" name="submit" value="Sum"><br> </form> <?php $sum1=$_POST['sum1']; $sum2=$_POST['sum2']; $sum3=$_POST['sum3']; $total_sum=$sum1+$sum2+$sum3; echo $total_sum; ?> </body> </html>
The result is a page with three boxes, where the numbers to be added should be filled, then press the sum button, the result will be printed in the screen.