Tsallaka zuwa abun ciki
Justice Tech School

Operators

Comparison: == != === !== < > <= >= and <=> (spaceship). Logical: && || ! and, or. ?? returns the left side if it exists and is not null, and ?: is the short ternary. Assignment shortcuts: += .= ++ --.

Example
$x = 10;
$x += 5;
echo $x, "\n";
var_dump(5 <=> 3);
$user = ["name" => "Ada"];
echo $user["city"] ?? "unknown", "\n";
echo $x > 10 ? "big" : "small", "\n";
$s = "a";
$s .= "b";
echo $s, "\n";

Result

15
int(1)
unknown
big
ab

Exercise

Use a default if the value is null.

$city = $input  "unknown";

Quiz Test

What does ?? do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.