saftutorials.com
PHP Operators Tutorial

PHP operators are used to performing some specific operation on variables and values.

What are PHP Operators?

PHP Operators operand one or more than one Operand.

These operators supported by PHP language.

-Assignment Operators

-Arithmetic Operators

-Comparison Operators

-Conditional / Ternary Operators

-Logical / Relational Operators


Assignment Operators

These are assignment operators which are supported by PHP language

Suppose $a = 30 and $b = 10

OperatorsNameDescriptionExample
=
Assign
Right variable value assign into left 
echo $a = $b   //output : 10
-=
Subtract Assign
Right variable value subtract from left and then assign into left
echo $a -= $b  //output : 20
+=
Add Assign
Right variable value add with left and then assign into left 
echo $a += $b  //output : 40
*=
Multiplication Assign 
Right variable value multiply by left and then assign into left 
echo $a *= $b  //output : 300
/= 
Devide Assign
Left variable value divide by right and then assign into left
echo $a /= $b  //output : 3
%=
Modulas Assign
Left variable value divide by right and then its remainder will assign into left
echo $a %= $b  //output : 0


Arithmetic Operators

These are arithmetic operators which are supported by PHP language

Suppose $a = 30 and $b = 10


Operators
NameDescriptionExample
+Addition
Addition of two operands
$a + $b  //output : 40
-Subtraction
 Subtract of two operands
$a - $b  //output : 20
*Multiplication
Multiplication of two operands
$a * $b  //output : 300
/Devide
Devide numerator by de-numerator 
$a / $b  //output : 3
%Modulas
Remainder of after an integer division
$a % $b  //output : 0
--Decrement 
Decrease integer value by one 
$a--     //output : 29
++Increament 
Increase integer value by one
$a++     //output : 31


Comparison Operators

These are comparison operators which are supported by PHP language

Suppose $a = 30 and $b = 10

OperatorsNameDescriptionExample
==Equal
Compare left operand equal to right
$a == $b  //output : false
===Identical
Compare left operand equal to right and both are the same type
$a === $b //output : false
!=Not equal
Compare left operand not equal to right
$a != $b  //output : false
!==Not identical
Compare left operand not equal to right and both are not the same type 
$a !== $b //output : false
>Greater than
Compare left operand is greater than right
$a > $b   //output : true
<Less than
Compare left operand is less than right
$a < $b   //output : false
>=Greater than or equal to
Compare left operand is greater than or equal to right
$a >= $b  //output : true
<=Less than or equal to
Compare left operand is less than or equal to right
$a <= $b  //output : false


Conditional / Ternary Operators

These are comparison operators which are supported by PHP language

Suppose $a = 30 and $b = 10

Operator
NameDescriptionExample
? :
Ternary
If condition true then first value print otherwise second
echo ($a == $b ? $a : $b); //output : 10


Logical / Relational Operators

These are logical/relational operators which are supported by PHP language

Suppose $a = 35 and $b = 0

Operators
NameDescriptionExample
&&Logical AND
If both operands are not zero then condition become true
($a && $b)   //output : false
||Logical OR
If one operand of them are not zero then condition become true
($a || $b)   //output : true
!Logical NOT 
If condition is true then logical not reverse the condition and make it false
!($a && $b)  //output : true


Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic