PHP Operators : Using Arithmetic Operators
Posted by Daniel at 12:37 pm
Using Arithmetic Operators in PHP you can perform mathematical operations on PHP variables. refer to the example below.
Using PHP Arithmetic Operator
//define variables <?php $num1 = 50; $num2 = 30; //Addition $sum = $num1 + $num2; //Subtraction $difference = $num1 - $num2; //Multiplication $product = $num1*$num2; //Division $quotient = $num1 / $num2; //Modulus $remainder = $num1 % $num2; ?>
you may also use the shorthand using the PHP Assignment Operator and Arithmetic Operator together.
PHP Assignment Operator and Arithmetic Operator Together
//define variables < ?php $num1 = 50; $num2 = 30; //Addition $num1 = $num1+ $num2; //Shorthand for this is.. $num1+=$num2; //Subtraction $num1 = $num1 - $num2; //Shorthand for this is.. $num1-=$num2; //Multiplication $num1 = $num1 * $num2; //Shorthand for this is.. $num1 *=$num2; //Division $num1 = $num1 / $num2; //Shorthand for this is.. $num1 /=$num2; //Modulus $num1= $num1 % $num2; //Shorthand for this is.. $num1%=$num2; ?>
That’s Right!…
This is a really good blog. Good work!…