PHP Operators
Operators perform calculations, comparisons and logical operations.
What is it?
Operators perform calculations, comparisons and logical operations.
Why do we use it?
Operators are required for calculations and decision making.
How does it work?
PHP evaluates an operator using one or more operands and produces a result.
Syntax
$a + $b; $a == $b; $a && $b;
Example
<?php $a = 10; $b = 5; echo $a + $b . "<br>"; echo $a > $b ? "A is greater" : "B is greater"; ?>
Example Explained
More Examples
<?php $x = true; $y = false; var_dump($x && $y); ?>
⚠️ Important Rules
Important groups include arithmetic, assignment, comparison, logical and string operators.
❌ Common Mistakes
Confusing = with == or ===.
🌍 Real-World Use
Operators are used throughout PHP applications.
📝 Practice Exercise
Create examples for arithmetic, comparison, assignment and logical operators.
💻 Try It Yourself
Write and run this PHP lesson inside the AIFA Coding Lab.