PHP 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.

<title>Arithmetic Operators for PHP</title>
<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>
echo $total_sum;

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.