Operators & Conditionals
Learn PHP arithmetic operators and how to make decisions with if/else statements. This is a foundational concept in server-side web development that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world PHP experience. Take your time with each section and practice the examples
25 min•By Priygop Team•Last updated: Feb 2026
PHP Operators & Conditionals
PHP supports all standard arithmetic operators. The . operator concatenates strings. Comparison operators return true or false. PHP's if/else works the same as JavaScript and C. PHP also has a === strict equality operator (checks value AND type) and a == loose equality operator.
PHP Operators
- + - * / % — Arithmetic operators
- . — String concatenation (unique to PHP)
- == — Loose equality (value only)
- === — Strict equality (value AND type)
- != !== > < >= <= — Comparison operators
- && || ! — Logical AND, OR, NOT
- += .= — Compound assignment
Operators & if/else Example
Example
<?php
$a = 10;
$b = 3;
echo $a + $b . "<br>"; // 13
echo $a - $b . "<br>"; // 7
echo $a * $b . "<br>"; // 30
echo $a / $b . "<br>"; // 3.333...
echo $a % $b . "<br>"; // 1
// String concatenation
$first = "Hello";
$last = "World";
echo $first . " " . $last . "<br>"; // Hello World
// if/else
$age = 18;
if ($age >= 18) {
echo "You are an adult.<br>";
} else {
echo "You are a minor.<br>";
}
// Grade checker
$score = 75;
if ($score >= 90) {
echo "Grade: A<br>";
} elseif ($score >= 80) {
echo "Grade: B<br>";
} elseif ($score >= 70) {
echo "Grade: C<br>";
} else {
echo "Grade: F<br>";
}
?>Try It Yourself: PHP Calculator
Try It Yourself: PHP CalculatorHTML
HTML Editor
✓ ValidTab = 2 spaces
HTML|46 lines|1515 chars|✓ Valid syntax
UTF-8