What is Operators in PHP?
Operators are symbols which tell the PHP processor that certain actions are performed. The Add (+) symbol, for example, is an operator who tells PHP to add two variables or values, while the larger (>) symbol is an operator who tells PHP to match two values. Do not presume that operators are functions alike. Such operators may be used instead of functioning (such as the PHP ternary).

- Arithmetic operators
- Assignment operators
- Comparison operators
- Increment/Decrement operators
- Logical operators
- String operators
- Array operators
- Spaceship operators
Arithmetic operators:-
The arithmetic operator is used for basic arithmetical operations like adding, removing, multiplying, etc. These operators can be used to execute simple arithmetic behaviour of numerical values. The following table shows how the results are used and what results are obtained.

- Operator Name Example Result
+Addition$x + $ySum of$xand$y-Subtraction$x - $yDifference of$xand$y*Multiplication$x * $yProduct of$xand$y/Division$x / $yQuotient of$xand$y%Modulus$x % $yRemainder of$xdivided by$y**Exponentiation$x ** $yResult of raising $x to the$y'thpower (Introduced in PHP 5.6)
Example:–
Output:-

Assignment operators:-
To assign values to variables, PHP Assignment operators are used. The left side of the operand variable is replaced with the right side value. Variables are assigned by operators in this group. The most common assignment operator is =, which assigns the right side of the operand to the variable on the left.

- Assignment Same as⦠Description
x = y x = yThe left operand gets set to the value of the expression on the rightx += y x = x + yAdditionx -= y x = x - ySubtractionx *= y x = x * yMultiplicationx /= y x = x / yDivisionx %= y x = x % yModulus
Example:-
Output:-

Comparison operators:-
The operator for a comparison indicates the relationship shared by a number or a series, by two or more values. These php operators are simply used to compare the numbers or strings of the two values. Here we will instruct you how to use php operators to compare them. This type of PHP operator is essential to search for any inconsistencies or correlations between values and variables. It functions as booleans, returning the True or false value. For example, if the two variables you compares are not equal in value, using PHP not equal to the operator would show real.

- Operator Name Example Result
==Equal$x == $yReturns true if $x is equal to$y===Identical$x === $yReturns true if $x is equal to $y, and they are of the same type!=Not equal$x != $yReturns true if$xis not equal to$y<>Not equal$x <> $yReturns true if$xis not equal to$y!==Not identical$x !==$yReturns true if$xis not equal to$y, or they are not of the same type>Greater than$x > $yReturns true if$xis greater than$y<Less than $x< $yReturns true if$xis less than$y>=Greater than or equal to$x >= $yReturns true if$xis greater than or equal to$y<=Less than or equal to$x <= $yReturns true if$xis less than or equal to$y
Example:-
Outputs:-

Increment/Decrement operators:-
These operators increase the value of a vector (increase) or decrease it (decrease). Often they are referred to as uniform operators since only one operator works. Operators for increasing and decreasing are employed to constantly increase or decrease a value by a factor of 1. Operator for pre-increment When added to the value, the new $x value is returned. For a clearer idea see the table below:

- Operator Name Description
++$xPre-increment Increments$xby one, then returns$x$x++Post-increment Returns$x,then increments$xby one--$xPre-decrement Decrements$xby one, then returns$x$x--Post-decrement Returns$x, then decrements$xby one
Example:-
Output:-

Logical operators:-
They mix conditionals and are used mostly to track various conditions simultaneously. The PHP (or) operator, for example, tests that at least one in two is valid. You can use the PHP (and) operator if you want to verify if they are both valid. See the following table for clarifications:

- Operator Name Example Result
- and And
$xand$yTrue if both$xand$yare true or Or $xor$yTrue if either$xor$yis truexor Xor$x xor $yTrue if either$xor$yis true, but not both- && And
$x && $yTrue if both$xand$yare true || Or$x || $yTrue if either$xor$yis true- !
Not !$xTrue if$xis not true
Example:-
Output:-

String operators:-
Two string operators are available. The use of numerical values could produce unpredictable results:
- The operator of PHP (.) is also known as the operator of concatenation. It connects individual strings.
- The operator of PHP (.=) is known as the operator of the combined assignment. It attaches the argument to the one on the left on the right page.

- Operator Name Example Result
.Concatenation$txt1 . $txt2Concatenation of$txt1and$txt2.=Concatenation assignment$txt1 .= $txt2Appends$txt2to$txt1
Example:-
Output:-

Array operators:-
For comparing arrays, the array operators are used. Use the operators mentioned below to compare different arrays. Be sure the right grammar is used.

- Operator Name Example Result
+Union$x + $yUnion of $x and $y==Equality$x == $yReturns true if$xand$yhave the same key/value pairs===Identity$x === $yReturns true if$xand$yhave the same key/value pairs in the same order and of the same types!=Inequality$x != $yReturns true if$xis not equal to$y<>Inequality$x <> $yReturns true if$xis not equal to$y!==Non-identity$x !== $yReturns true if$xis not identical to$y
Example:-
Output:-

Spaceship operators:-
PHP 7 adds a new spacecraft operator (<=>) that can be used to compare two terms. The combined contrast operator is also known.
If the two operands are identical, the spacecraft operator returns 0, 1 if the left is larger, and -1 if the right is larger. The three-way comparison is essentially shown as seen in the next table:

Example:-
Output:-


π€ About the Author
Ashwani is passionate about DevOps, DevSecOps, SRE, MLOps, and AiOps, with a strong drive to simplify and scale modern IT operations. Through continuous learning and sharing, Ashwani helps organizations and engineers adopt best practices for automation, security, reliability, and AI-driven operations.
π Connect & Follow:
- Website: WizBrand.com
- Facebook: facebook.com/DevOpsSchool
- X (Twitter): x.com/DevOpsSchools
- LinkedIn: linkedin.com/company/devopsschool
- YouTube: youtube.com/@TheDevOpsSchool
- Instagram: instagram.com/devopsschool
- Quora: devopsschool.quora.com
- Email– contact@devopsschool.com