PHP Operators

By | September 27, 2022

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
  • Comparison Operators
OperatorDescriptionExample
==is equal to5==8 returns false
!=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
Category: PHP

Leave a Reply

Your email address will not be published. Required fields are marked *