PHP Operators
Operators are used to calculate values using PHP.
Think of all the different operators as different buttons on a calculator. Each button calculates a value differently, and each PHP operator calculates a value differently.
If you remember simple algebra, many of these operators will look familiar to you, such as greater than (>) and less than (<). However, there are many other operators that can be used with PHP, which can be divided into four groups: Arithmetic, Assignment, Comparison and Logical operators.
Arithmetic Operators
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus (the remainder value of after a division)
++
Increment (increase by a specific number)
–
Decrement (decrease by a specific number)
Examples:
2+2
5-3
5*5
20/4
5%2
$i++ (the value of the string $i would increase by 1)
$i– (the value of the string $i would decrease by 1)
Assignment Operators
Assignment operators are not used as regularly as arithmetic or comparison operators, but they are still good to know.
=
x=y is the same as x=y
+=
x+=y is the same as x=x+y
-=
x-=y is the same as x=x-y
*=
x*=y is the same is x=x*y
/=
x/=y is the same as x=x/y
.=
x.=y is the same as x=x.y
%=
x%=y is the same as x=x%y
Comparison Operators
==
Is Equal To
!=
Is Not Equal To
<
Is Less Than
>
Is Greater Than
<=
Is Less Than or Equal To
>=
Is Greater Than or Equal To
Examples:
8 == 8
1 != 2
2 < 8
8 > 2
4 <= 7
7 >= 7
Logical Operators
&&
And
||
Or
!
Not
Concentration Operator
The concentration operator is used to join multiple strings together by using a period (.).
For an example of how to use the concentration operator, see PHP strings.




