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.

OperatorDescriptionExample
+Addition$a + $b
-Subtraction$a - $b
*Multiplication$a * $b
/Division$a / $b
%Modulus (remainder)$a % $b
**Exponentiation$a ** $b

Example:

$a = 10; $b = 3; echo $a + $b; // 13

2. Assignment Operators

Used to assign values to variables.

OperatorDescription
=Assign
+=Add and assign
-=Subtract and assign
*=Multiply and assign
/=Divide and assign
%=Modulus and assign

Example:

$x = 5; $x += 3; // 8

3. Comparison Operators

Used to compare two values.

OperatorDescription
==Equal
===Identical (value + type)
!=Not equal
!==Not identical
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal
<=>Spaceship

Example:

var_dump(5 === "5"); // false

4. Logical Operators

Used for combining conditions.

OperatorDescription
&&AND
`
!NOT
andAND
orOR

Example:

if ($age > 18 && $active) { echo "Access granted"; }

5. Increment / Decrement Operators

OperatorDescription
++$aPre-increment
$a++Post-increment
--$aPre-decrement
$a--Post-decrement

Example:

$i = 5; echo $i++; // 5 echo $i; // 6

6. String Operators

OperatorDescription
.Concatenation
.=Concatenate and assign

Example:

$name = "John"; echo "Hello " . $name;

7. Array Operators

OperatorDescription
+Union
==Equal
===Identical
!=Not equal

Example:

$a = ["a" => 1]; $b = ["b" => 2]; $c = $a + $b;

8. Conditional (Ternary) Operator

$status = ($age >= 18) ? "Adult" : "Minor";

9. Null Coalescing Operator

Used to handle null values.

$username = $_GET['user'] ?? 'Guest';

10. Type Operators

OperatorDescription
instanceofChecks object type

Example:

if ($obj instanceof User) { // }

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

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes