Operators in PHP
📘 PHP
👁 28 views
📅 Dec 22, 2025
⏱ Estimated reading time: 2 min
Operators in PHP are symbols used to perform operations on variables and values. They are essential for calculations, comparisons, decision-making, and logical processing in PHP programs.
1. Arithmetic Operators
Used for mathematical operations.
| Operator | Description | Example |
|---|---|---|
+ | Addition | $a + $b |
- | Subtraction | $a - $b |
* | Multiplication | $a * $b |
/ | Division | $a / $b |
% | Modulus (remainder) | $a % $b |
** | Exponentiation | $a ** $b |
Example:
2. Assignment Operators
Used to assign values to variables.
| Operator | Description |
|---|---|
= | Assign |
+= | Add and assign |
-= | Subtract and assign |
*= | Multiply and assign |
/= | Divide and assign |
%= | Modulus and assign |
Example:
3. Comparison Operators
Used to compare two values.
| Operator | Description |
|---|---|
== | Equal |
=== | Identical (value + type) |
!= | Not equal |
!== | Not identical |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
<=> | Spaceship |
Example:
4. Logical Operators
Used for combining conditions.
| Operator | Description |
|---|---|
&& | AND |
| ` | |
! | NOT |
and | AND |
or | OR |
Example:
5. Increment / Decrement Operators
| Operator | Description |
|---|---|
++$a | Pre-increment |
$a++ | Post-increment |
--$a | Pre-decrement |
$a-- | Post-decrement |
Example:
6. String Operators
| Operator | Description |
|---|---|
. | Concatenation |
.= | Concatenate and assign |
Example:
7. Array Operators
| Operator | Description |
|---|---|
+ | Union |
== | Equal |
=== | Identical |
!= | Not equal |
Example:
8. Conditional (Ternary) Operator
9. Null Coalescing Operator
Used to handle null values.
10. Type Operators
| Operator | Description |
|---|---|
instanceof | Checks object type |
Example:
Conclusion
Operators in PHP are fundamental building blocks for performing calculations, making decisions, and processing data. A solid understanding of operators helps you write efficient and logical PHP code, especially when moving toward advanced topics and frameworks like Laravel.
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials