Arithmetic Operators in PHP

Arithmetic operators are one of the sorts of operators in the PHP programming language. The arithmetic operators are very valuable for many mathematical estimations to do various types of programs to ease our problem-solving tasks. Arithmetic operators can be used only with the numerical values/numbers to perform arithmetic operations like Addition (+), Subtraction (-), Multiplication (x), Division (/), Modulus (%), and Exponentiation (**)(1st number to the power of 2nd number ).

Arithmetic Operators in PHP

1. Addition (+)

The addition is one of the Arithmetic operators of the PHP programming language. It needs at least two values or numbers to add.

<?php
$first = 35;
$second = 34;
$sum = $first + $second;
echo "First Variable Value : $first";
echo "<br/>";
echo "Second Variable Value : $second";
echo "<br/>";
echo "The sum of the two variables: ";
echo $sum;
?>
Output
69

Subtraction (-)

Subtraction is one of the Arithmetic operators of the PHP programming language. It needs at least two values or numbers to subtract.

Read Also: How to Declare Variables in PHP

<?php
$first = 35;
$second = 34;
$sum = $first - $second;
echo "First Variable Value : $first";
echo "<br/>";
echo "Second Variable Value : $second";
echo "<br/>";
echo "The sum of the two variables: ";
echo $sum;
?>
Output
1

Multiplication (x)

Multiplication is one of the Arithmetic operators of the PHP programming language. It needs at least two numerical values to multiply.

<?php
$first = 35;
$second = 34;
$sum = $first * $second;
echo "First Variable Value : $first";
echo "<br/>";
echo "Second Variable Value : $second";
echo "<br/>";
echo "The sum of the two variables: ";
echo $sum;
?>
Output
1190

Division (/)

The division is one of the Arithmetic operators of the PHP programming language. It needs at least two numbers to divide.

<?php
$first = 10;
$second = 5;
$sum = $first / $second;
echo "First Variable Value : $first";
echo "<br/>";
echo "Second Variable Value : $second";
echo "<br/>";
echo "The sum of the two variables: ";
echo $sum;
?>
Output
2

Modulus (%)

Modulus is one of the Arithmetic operators of this programming language. It needs at least two numbers to know the remainder value. You will get only number 1 or number 0 values for the remainder when you divide a number with any other number, but if you divide with a significant number, you will definitely get 0 value for that.

<?php
$x = 10;  
$y = 6;

echo $x % $y;
?> 
Output
4int(700)
int(35)

Conclusion

I think you understood what is meant by Addition (+), Subtraction (-), Multiplication (x), Division (/), and Modulus (%).

Leave a Reply

Your email address will not be published. Required fields are marked *