PHP operators

PHP operator

Operators are used to calculating values.

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators

Arithmetic operators

+To add two number2+3=5
To subtract two number3-2=1
*To multiply number3*2=6
/To divide the number, return the quotient3/2=1.5
%To divide the number, return the remainder3/2= 1
List of arithmetic operators

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
List of relational operators

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.
List of logical operators

Example:

<?php
echo 2>=3 && 2>=1;
echo 2>=5 || 2>1;
if(! 2>3){
   echo "True";
}else{
   echo "False";
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *