PHP Operators

Arithmetic, comparison, logical and more.

✍️ 2 exercises in this lesson
  • Arithmetic: + - * / % **
  • Assignment: = += -= *= /= .=
  • Comparison: == equal value, === identical (value and type), !=, !==, <=> spaceship
  • Logical: &&, ||, !
  • String: . join, .= append
  • Null coalescing: $a ?? "default"
  • Ternary: $cond ? "yes" : "no"

Key Takeaways: PHP Operators

Mastering PHP Operators helps you write clean and reliable PHP code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

PHP Operators Code Example

PHP
<?php
$x = 10;
$x += 5;
echo $x . "<br>";

var_dump("5" == 5);
var_dump("5" === 5);
echo (3 <=> 7) . "<br>";

$user = null;
echo $user ?? "Guest";
echo "<br>" . ($x > 10 ? "big" : "small");
Output
15
bool(true)
bool(false)
-1
Guest
big
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

PHP Operators Practice Exercises

Check what you learned in “PHP Operators”.

/ 2 solved
Fill in the blank

Use the null coalescing operator for a default value.

$user = $_GET["user"]  "Guest";
✓ Correct! Not quite. Try again.
Multiple choice

What does === check?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services