PHP Operators

There are many operators used in PHP. Operators are used to operate on values.

Below are the operators used in PHP


Arithmetic Operators

Operator Description Example Result
+ Addition x=3
x+3
6
- Subtraction x=4
9-x
5
* Multiplication x=5
x*7
35
/ Division 15/3
7/2
5
3.5
% Modulus (division remainder) 7%2
12%8
6%2
1
4
0
++ Increment x=9
x++
x=10
Decrement x=9
x–
x=8

Assignment Operators

Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y

Comparison Operators

Operator Description Example
== is equal to 6==9 returns false
!= is not equal 6!=9 returns true
<> is not equal 6<>9 returns true
> is greater than 6>9 returns false
< is less than 6<9 returns true
>= is greater than or equal to 6>=9 returns false
<= is less than or equal to 6<=9 returns true

Logical Operators

Operator Description Example
&& and x=6
y=3(x < 10 && y > 1) returns true
|| or x=6
y=3(x==5 || y==5) returns false
! not x=6
y=3!(x==y) returns true






Related Posts:

Comments are closed.