Operators operate on variables and produce calculated results such as additions or multiplications or comparisons. In PHP, following are operators are available.
Arithmetic Operators
Comparison Operators
Logical Operators
Assignment Operators
Let’s discuss each operator one by one.
Arithmetic operators
Operator
Description
+
Adds two operands
–
Subtracts right operand from the left operand
*
Multiplies two operands
/
Divides left operand by right operand
%
Modulus operation (remainder of left operand divided by right operand)
Condition is true only when value of two operands are same
!=
Condition is true only when value of both operands is different
<
Condition is true only when value of first operand is less than second operand
>
Condition is true only when value of first operand is greater than second operand
<=
Condition is true only when value of first operand is less than or equal to second operand
>=
Condition is true only when value of first operand is greater than or equal to second operand
<?php
$KH_Operand1 = 55;
$KH_Operand2 = 15;
if ($KH_Operand1 == $KH_Operand2)
echo "Operand1 is equal to Operand2 <br/>";
else
echo "Operand1 is not equal to Operand2 <br/>";
if ($KH_Operand1 < $KH_Operand2)
echo "Operand1 is less than Operand2 <br/>";
else
echo "Operand1 is not less than Operand2 <br/>";
if ($KH_Operand1 > $KH_Operand2)
echo "Operand1 is greater than Operand2 <br/>";
else
echo "Operand1 is not greater than Operand2 <br/>";
if ($KH_Operand1 <= $KH_Operand2)
echo "Operand1 is less or equal to Operand2 <br/>";
else
echo "Operand1 is not less or equal to Operand2 <br/>";
if ($KH_Operand1 >= $KH_Operand2)
echo "Operand1 is greater or equal to Operand2 <br/>";
else
echo "Operand1 is not greater or equal to Operand2 <br/>";
if ($KH_Operand1 != $KH_Operand2)
echo "Operand1 is not equal to Operand2 <br/>";
else
echo "Operand1 is equal to Operand2 <br/>";
?>