# PHP Operators

To **carry out operations** on **variables and values**, operators are employed.

In the following groupings **PHP splits** the operators :

- Arithmetic operators
- Assignment operators
- Comparison operators
- Increment/Decrement operators
- Logical operators
- String operators
- Array operators
- Conditional assignment operators

**operators in php, types of operators in php, how many operators in php, list out the operators available in php, what is php operators?.**

## PHP Arithmetic Operators

The PHP arithmetic operators are used in **conjunction with numeric dat**a to execute standard arithmetic operations like as **addition, subtraction, multiplication**, and so on.

**Example :-** Consider, There are two variables called **$a = 12 and $b = 5**

Operator | Name | Example | Result |
---|---|---|---|

+ | Addition | $a + $b | 17 |

- | Subtraction | $a - $b | 7 |

* | Multiplication | $a * $b | 60 |

/ | Division | $a / $b | 2.4 |

% | Modulus | $a % $b | 2 |

** | Exponentiation | $a ** $b | End of $a and $b |

**php arithmetic operators, php arithmetic sequence, php arithmetic operators variables, php arithmetic operators example, php arithmetic operations, php arithmetic operators table.**

## PHP Assignment Operators

With numerical numbers, the PHP assignment operators are used to **type a value into a variable**.

The "=" assignment operator is the most fundamental assignment operator in **PHP**. It signifies that the value of the assignment expression on the **right is assigned to the left operand.**

Assignment | Same As | Description | |
---|---|---|---|

a = b | a = b | The left operand gets set to the value of the expression on the right | |

a+=b | a = a+b | Addition | |

a-=b | a = a-b | Subtraction | |

a*=b | a = a*b | Multiplication | |

a/=b | a = a/b | Division | |

x%=y | x = x%y | Modulus |

**php assignment operators, php assignment sequence, php assignment operators variables, php assingnment operators example, php assignment operations, php assignment operators table.**

## PHP Comparison Operators

**Two values** (number or string) are **compared** with **PHP** comparison operators.

**Example :-** Consider, There are two variables called **$a = 12 and $b = 5**

Operator | Name | Example | Description | Result |
---|---|---|---|---|

== | Equal | $a == $b | Returns true if $a is equal to $b | FALSE |

=== | Identical | $a === $b | Returns true if $x is equal to $y, and they are of the same type | FALSE |

!= | Not Equal | $a != $b | Returns true if $a is not equal to $b | TRUE |

<> | Not Equal | $a <> $b | Returns true if $a is not equal to $b | TRUE |

!== | Not Identical | $a !== $b | Returns true if $a is not equal to $b, or they are not of the same type | FALSE |

> | Greater Than | $a > $b | Returns true if $a is greater than $b | TRUE |

< | Less Than | $a < $b | Returns true if $a is less than $b | FALSE |

>= | Greater Than or Equal to | $a >= $b | Returns true if $a is greater than or equal to $b | TRUE |

<= | Less Than or Equal to | $a <= $b | Returns true if $a is less than or equal to $b | FALSE |

<=> | Spaceship | $a <=> $b | Returns an integer less than, equal to, or greater than zero, depending on if $a is less than, equal to, or greater than $b. |

**php comparison operators, php comparison sequence, php comparison operators variables, php comparision operators example, php comparision operations, php comparision return value, php comparison operators table.**

## PHP Increment / Decrement Operators

The **PHP increment** functionality is used to **increase the value of the variable.**

**decreasing PHP** operators are used to **decreasing the value of the variable.**

Operator | Name | Description |
---|---|---|

++$a | Pre-Increment | Increments $a by one, then returns $a |

$a++ | Post-Increment | Returns $a, then increments $a by one |

--$a | Post-Decrement | Returns $a, then decrements $a by one |

**Related Links**

**php increment/decrement operators, php increment/decrement sequence, php increment/decrement operators variables, php increment/decrement operators example, php increment/decrement operations, php increment/decrement return value, php increment operators, php decrement operators, type of increment/decrement operators, php increment/decrement table.**

## PHP Logical Operators

To **match conditional statements**, PHP logical operators are utilized.

Operator | Name | Example | Result |
---|---|---|---|

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 || $1b | True if either $a or $b is true |

! | Not | !$a | True if $a is not true |

**php logical operators, php logical sequence, php logical operators variables, php logical operators example, php logical operations, php logical operators table.**

## PHP String Operators

String operators are provided by **PHP** in the form of two operators.

Operator | Name | Example | Result |
---|---|---|---|

. | Concatenation | $msg1 . $msg2 | Concatenation of $msg1 and $msg2 |

.= | Concatenation assignment | $msg1 .= $msg2 | $msg1 .= $msg2 Appends $msg2 to $msg1 |

**php string operators, php string sequence, php string operators variables, php string operators example, php string operations, php string operators table, php string operators list.**

## PHP Array Operators

For the **comparison of arrays**, PHP array operators are utilized.

Operator | Name | Example | Result |
---|---|---|---|

+ | Union | $a + $b | Union of $a and $b |

== | Equality | $a == $b | Returns true if $x and $y have the same key/value pairs |

=== | Identity | $a === $b | Returns true if $x and $y have the same key/value pairs in the same order and of the same types |

!= | In Equality | $a != $b | Returns true if $a is not equal to $b |

<> | In Equality | $a <> $b | Returns true if $a is not equal to $b |

!== | Not Identity | $a !== $b | Returns true if $x is not identical to $y |

**Related Links**

**php array operators, php array sequence, php array operators variables, php array operators example, php array operations, php comparision return value, php array operators table.**

## PHP Conditional Assignment Operators

In order to **set a value dependent of conditions**, the PHP conditional assignment operators will :

Operator | Name | Example | Result |
---|---|---|---|

?: | Tenary | $a = expr1 ? expr2 : expr3 | Returns the value of $x. The value of $a expr2 if expr1 = TRUE. The value of $a is expr3 if expr1 = FALSE |

?? | Null coalescing | $a = expr1 ?? expr2 | Returns the value of $a. The value of $a is expr1 if expr1 exists, and is not NULL. If expr1 does not exist, or is NULL, the value of $a is expr2. Introduced in PHP 7 |

**php conditional assignment operators, php conditional assignment sequence, php conditional assignment operators variables, php conditional assignment operators example, php conditional assignment operations, php conditional assignment return value, php conditional assignment operators table.**