# PHP Operator

Operator could be given using term 4 + 7 is equal to 11. Here 4 and 7 are called operands and + is called operator.

** PHP supports subsequent type of operators:-**

• Arithmetic Operators

• Comparison Operators

• Logical (or Relational) Operators

• Assignment Operators

• Conditional (or ternary) Operators

**Arithmetic Operators:-**

These operators are used with numeric values to execute universal arithmetical operations, such as addition, subtraction etc.

**Example:-**

Operator |
Description |
Example |

+ | Adds two operands | 5 + 1 will give 6 |

– | Subtracts second operand from the first | 5 – 1 will give 4 |

* | Multiply both operands | 4 * 5 will give 20 |

/ | Divide numerator by de-numerator | 5 / 1 will give 5 |

% | Modulus Operator and remainder of after an integer division | 5% 1 will give 0 |

++ | Increment operator, increases integer value by one | 5++ will give 6 |

— | Decrement operator, decreases integer value by one | 5– will give 4 |

**Comparison Operators:-**

These operators are used for comparison.

**Example:-**

Operator |
Description |
Example |

== | Checks if the value of two operands is equal or not, if yes then condition becomes true. | (5 == 1) is not true. |

!= | Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. | (5 != 1) is true. |

> | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (1> 5) is not true. |

< | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (1 < 5) is true. |

>= | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (1 >= 5) is not true. |

<= | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (1 <= 1) is true. |

**Logical Operators:-**

These operators are used for logical functions.

**Example:-**

Operator |
Description |
Example |

and | Called Logical AND operator. If both the operands are true then condition becomes true. | (K and Z) is true. |

or | Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. | (K or Z) is true. |

&& | Called Logical AND operator. If both the operands are non zero then condition becomes true. | (K && Z) is true. |

|| | Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. | (K || Z) is true. |

! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(K && Z) is false. |

**Assignment Operators:-**

There are subsequent assignment operators.

**Example:-**

Operator |
Description |
Example |

= | Simple assignment operator, Assigns values from right side operands to left side operand | K = L + M will assign value of L + M into K |

+= | Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand | K += L is equivalent to K = K + L |

-= | Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand | K-= L is equivalent to K = K – L |

*= | Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand | K*= L is equivalent to K = K * L |

/= | Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand | K/= L is equivalent to K = K / L |

%= | Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand | K %= L is equivalent to K = K % L |

**Conditional Operator:-**

This operator evaluates an expression for a true or false value and then executes one of the two given declarations depending upon the result of the assessment.

**Example:-**

Operator |
Description |
Example |

? : | Conditional Expression | If Condition is true ? Then value K : Otherwise value M |