PHP Operators

55

Operators are used to operate on values.


PHP Operators

This section lists the different operators used in PHP.

Arithmetic Operators

OperatorDescriptionExampleResult
+Additionx=2
x+2
4
Subtractionx=2
5-x
3
*Multiplicationx=4
x*5
20
/Division15/5
5/2
3
2.5
%Modulus (division remainder)5%2
10%8
10%2
1
2
0
++Incrementx=5
x++
x=6
Decrementx=5
x–
x=4

Assignment Operators

OperatorExampleIs The Same As
=x=yx=y
+=x+=yx=x+y
-=x-=yx=x-y
*=x*=yx=x*y
/=x/=yx=x/y
.=x.=yx=x.y
%=x%=yx=x%y

PHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP OperatorsPHP Operators

Comparison Operators

OperatorDescriptionExample
==is equal to5==8 returns false
!=is not equal5!=8 returns true
<>is not equal5<>8 returns true
>is greater than5>8 returns false
<is less than5<8 returns true
>=is greater than or equal to5>=8 returns false
<=is less than or equal to5<=8 returns true

Logical Operators

OperatorDescriptionExample
&&andx=6
y=3(x < 10 && y > 1) returns true
||orx=6
y=3(x==5 || y==5) returns false
!notx=6
y=3!(x==y) returns true

 

loading...
SHARE

LEAVE A REPLY