Operators are used to calculating values.
- Arithmetic Operators
- Relational Operators
- Logical Operators
Arithmetic operators
+ | To add two number | 2+3=5 |
– | To subtract two number | 3-2=1 |
* | To multiply number | 3*2=6 |
/ | To divide the number, return the quotient | 3/2=1.5 |
% | To divide the number, return the remainder | 3/2= 1 |
Example
<?php
echo 2+3;
echo 3-2;
echo 3*2;
echo 3/2;
echo 3%2;
?>
Relational operators
These operators are used to check the relation between two operands for one operand is less, less than or equal, greater, greater than or equal, etc.
Note:
Relational operators return boolean value (true/false)
< | Return true if left side operand is less than right side operand otherwise false |
<= | Return true if left side operand is less than or equal to right-side operand otherwise false |
> | Return true if left side operand is greater than right-side operand otherwise false |
>= | Return true if left side operand is greater than or equal to right side operand otherwise false |
!= | Return true if left side operand is not equal to right side operand otherwise false |
== | Return true if left side operand is equal to right side operand otherwise false |
Example:
<?php
echo 2<3;
echo 2<=3;
echo 2>3;
echo 2>=3;
echo 2!=3;
echo 2==3;
?>
Logical operators
AND (&&) | Return true if both conditions are true otherwise false |
OR ( || ) | Return true if one of the conditions from given conditions otherwise false |
NOT ( ! ) | Return true if the condition is false and false if the condition is true. |
Example:
<?php
echo 2>=3 && 2>=1;
echo 2>=5 || 2>1;
if(! 2>3){
echo "True";
}else{
echo "False";
}
?>