PHP tutorial-PHP operators

PHP operators

Assignment Operator

= sign is used as the assignment operator in PHP. The assignment operator is used to assing a value to a variable.



Arithmetic operators

Operator Description Example Result
+ Addition a=1+2 3
- Subtraction a=3-1 2
* Multiplication a=2*5 10
/ Division 10/2 5
% Modulus (division remainder) 10%2 0
++ Increment a=3 a++   a=4
-- Decrement a=3 a-- a=2


Comparison operators

The comparison operators as shown below are used to compare two variables or expressions. The result of the comparison operation can be true or false.

Operator Description Example
== equal to 1==2 evaluated to false
!= not equal 1!=2 evaluated to true
> greater than 1>2 evaluated to false
< less than 1<2 evaluated to true
>= greater than or equal to 1>=2 evaluated to false
<= less than or equal to 1<=2 evaluated to true

Logical Operators

The logical operations are used to do the logical operations of two variables or expressions. We have three logical operators in PHP. The && operator represents the logical and operation. The || operator represents the logical or operation. And the ! operator represents the logical not operation. 


Operator Description Example
&& and x=1 y=2 (x < 5 && y > 1) evaluated to true
|| or x=1 y=2 (x>2 || y>1) evaluated to true
! not x=1 y=2 !(x==y) evaluated to true


Compound Operators

Each compound operator combines two operators together. For example a compound operator might combines the adding operator and the assignment operator.

Operator Example The Same As
+= 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

Sting concatenation operator (.)

In PHP, the point symbol (.) is used to concatenate strings.




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.