
PHP operators are used to performing operations on variables and values.
- Maths Operators
- Assignment operators
- Logical Operators
- Increment and Decrement Operators
- String Operators
Maths Operators:-
arithmetic operators are used with numerice values to perform arithmetic operators like as addition, subtraction, multiplication, division or etc.
ex:-
<?php | |
//Maths operators | |
echo 4+5; | |
echo 5-2; | |
echo 4*9; | |
echo 25/5; | |
?> |
Assignment operators:-
Assignment operators are used to write a numeric value to a variable values.
ex:-
<?php | |
//assignment operators | |
$num = 25; | |
$num1 = 25; | |
$num2 = 25; | |
echo $num; | |
echo $num1; | |
echo $num2; | |
$num = $num1 = $num2 = 25; | |
echo $num. "<br>"; | |
echo $num1; | |
echo $num2; | |
?> |
Logical Operators:-
Logical operators are used to write combine conditional operators.
ex:-
<?php | |
/* | |
and And $a and $b True if both $a and $b are true | |
or Or $a or $b True if either $a or $b is true | |
xor Xor $a xor $b True if either $a or $b is true, but not both | |
&& And $a && $b True if both $a and $b are true | |
|| Or $a || $b True if either $a or $b is true | |
! Not !$a True if $a is not true */ | |
if ((5>4) && (2<1)) | |
{ | |
echo "this is true <br>"; | |
} | |
else | |
{ | |
echo "this is wrong <br>"; | |
} | |
//output this is wrong | |
if ((9>8) and (2<6)) | |
{ | |
echo "this is true <br>"; | |
} | |
else | |
{ | |
echo "this is wrong <br>"; | |
} | |
//output this is true | |
if ((9>8) or (2<6)) | |
{ | |
echo "this is true <br>"; | |
} | |
else | |
{ | |
echo "this is wrong <br>"; | |
} | |
//output this is true | |
if ((9>8) xor (2<6)) | |
{ | |
echo "this is true <br>"; | |
} | |
else | |
{ | |
echo "this is wrong <br>"; | |
} | |
//output this is wrong | |
if ((9>8) || (2<6)) | |
{ | |
echo "this is true <br>"; | |
} | |
else | |
{ | |
echo "this is wrong <br>"; | |
} | |
//output this is true | |
?> |
Increment and Decrement Operators:-
Increment and Decrement operators are used to increment and decrement a variableβs values to print.
ex:-
<?php | |
/* | |
++$a Pre-increment Increments $a by one, then returns $a | |
$a++ Post-increment Returns $a, then increments $a by one | |
--$a Pre-decrement Decrements $a by one, then returns $a | |
$a-- Post-decrement Returns $a, then decrements $a by one*/ | |
$a = 3; | |
echo ++$a; | |
// echo $d--; | |
echo "<br>"; | |
$a = 5; | |
echo ++$a; | |
// echo --$c; | |
echo "<br>"; | |
$c = 9; | |
echo --$c; | |
echo "<br>"; | |
$d = 11 + 12; | |
echo $d--; | |
echo "<br>"; | |
$e = $a + $c; | |
echo $e; | |
echo "<br>"; | |
?> |
String Operators:-
String operators are used to combine variable and values this called as Concatenation and Concatenation assignment.
ex:-
<?php | |
/*. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2 | |
.= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1*/ | |
$name = "devops "; | |
$name1 = "school "; | |
echo $name , $name1; //PHP Important Operators for beginners | |
echo "<br>"; | |
$num = "this is "; | |
$num2 = "operators "; | |
echo $num, $num2, "examples"; | |
?> |




Iβm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND