Arithmetic Operators

Back to index

x = 20, y = 6

Addition (+)

20 + 6 = 26

The plus sign is used to add two numbers together. In this example, 20 and 6 are added, so the answer is 26. I would use this operator when I need to find the total of two or more numbers.

Subtraction (-)

20 - 6 = 14

The minus sign is used to subtract one number from another number. Here, 6 is taken away from 20, which gives 14. This can be useful when finding the difference between two numbers.

Multiplication (*)

20 * 6 = 120

The asterisk is used for multiplication in PHP. In this example, 20 is multiplied by 6 and the answer is 120. It is useful when calculating totals, such as the price of several items with the same cost.

Division (/)

20 / 6 = 3.33

The slash is used to divide one number by another number. In this example, 20 is divided by 6 and the result is about 3.33. Division is useful when splitting a number into equal parts.

Modulus (%)

20 % 6 = 2

The percent sign is the modulus operator. It gives the remainder after one number is divided by another number. When 20 is divided by 6, the remainder is 2. This can be useful for checking if numbers divide evenly.

Exponent (**)

6 ** 2 = 36

The two asterisks are used for exponentiation. They raise a number to a power. In this example, 6 is raised to the second power, which means 6 times 6, giving an answer of 36.