Arithmetic Operators in php

The arithmetic operators are operators you’ll recognize from everyday use. Most of the arithmetic operators are binary; however, the arithmetic negation and arithmetic assertion operators are unary

The arithmetic operators are:

Addition (+)

The result of the addition operator is the sum of the two operands

Subtraction (−)

The result of the subtraction operator is the difference between the two operands —i.e., the value of the second operand subtracted from the first

Multiplication (*)

The result of the multiplication operator is the product of the two operands. For example, 3 * 4 is 12.

Division (/)

The result of the division operator is the quotient of the two operands. Dividing two integers can give an integer (e.g., 4 / 2) or a floating-point result (e.g., 1 / 2).

Modulus (%)

The modulus operator converts both operands to integers and returns the remainder of the division of the first operand by the second operand. For example, 10 % 6 is 4.

Arithmetic negation (−)

The arithmetic negation operator returns the operand multiplied by −1, effectively changing its sign. For example, −(3 − 4) evaluates to 1. Arithmetic negation is different from the subtraction operator, even though they both are written as a minus sign. Arithmetic negation is always unary and before the operand. Subtraction is binary and between its operands

Arithmetic assertion (+)

The arithmetic assertion operator returns the operand multiplied by +1, which has no effect. It is used only as a visual cue to indicate the sign of a value. For example, +(3 − 4) evaluates to −1, just as (3 − 4) does.

Leave a Comment