Last updated on September 2, 2023 by Siraj Ul Haq

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.

Operator | Name | Syntax | Operation |

+ | Addition | $x + $y | Sum the operands |

– | Subtraction | $x – $y | Differences the operands |

* | Multiplication | $x * $y | Product of the operands |

/ | Division | $x / $y | The quotient of the operands |

** | Exponentiation | $x ** $y | $x raised to the power $y |

% | Modulus | $x % $y | The remainder of the operands |

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

Share on:

Related Posts

Published on 25 September

Published on 21 September

Published on 19 September

Published on 18 September

Published on 17 September