# What is the Arithmetic Operator in PHP?

Last updated on September 2, 2023

We use arithmetic operators in PHP to perform simple mathematical operations. As like addition, subtraction, multiplication, division, exponentiation, and modulus operations. The arithmetic operators require numeric values. If you apply an arithmetic operator to non-numeric values, it’ll convert them to numeric values before performing the arithmetic operation. Let’s try to understand with the help of a list.

Below is the list of arithmetic operators along with their syntax and operations in PHP.

Example 01:

``````\$a = 42;
\$b = 20;
\$c = \$a + \$b;
echo \$c;
// output: 62``````

In the above example, the Addition Operator is used to add two Values. Suppose a and b are two Values; these plus operators will add up these two Values a + b.

Example 02:

``````\$a = 42;
\$b = 20;
\$c = \$a - \$b;
echo \$c;
// output: 02
``````

In the above example, the Addition Operator is used to subtract two values. Suppose a and b are two Values; then this minus operator will subtract the value of the second value from the first value.

Example 03:

``````\$a = 42;
\$b = 20;
\$c = \$a * \$b;
echo \$c;
//Output: 840
``````

In the above example, a Multiplication Operator is used to multiply two Values. Suppose a and b are two Values; then this multiplication operator will multiply a with b.

Example 04:

``````\$a = 42;
\$b = 20;
\$c = \$a / \$b;
echo \$c;
//Output: 2.1
``````

In the above example, Division Operator is used to numerator by the denominator. Suppose a and b are two Values; this division operator divides the numerator by the denominator.

Example 05:

``````\$a = 42;
\$b = 20;
\$c = \$a % \$b;
echo \$c;
//Output: 2.1
``````

In the above example, a Modulus Operator gives the remainder of the division.  Suppose a and b are two Values; this modulus operator divides the numerator by the denominator and gives the remainder.

Example 06:

``````\$a = 42;
\$b = 20;
\$c = \$a ** \$b;
echo \$c;
//Output: 2.1
``````

In the above example, an exponential Operator is used to raise one quantity to the power of another value. Suppose a and b are two Values; then this exponentiation operator raises the value of a to the power b.

Conclusion:

In the above article, we explained arithmetic operators with different examples. Also it has a table containing all the operators along with symbols and defination.

Written by

#### Siraj Ul Haq

I am Siraj, a results-driven web developer with three years of hands-on experience in both frontend and backend development. My passion for creating seamless digital experiences drives me to continuously innovate and excel in my field.

Share on:

Related Posts

Tags: PHP,