PHP Operators
Arithmetic + - * / % **, comparison == === != !== < >, logical && || ! (or and, or), and the null coalescing operator ??.
ExamplePHP
<?php
var_dump(5 == "5"); // loose: equal after conversion
var_dump(5 === "5"); // strict: same type and value
var_dump(5 <=> 3); // spaceship: 1, 0 or -1
$user = null;
echo $user ?? "guest", "\n"; // default when null
$x = 10;
$x .= " apples";
echo $x, "\n";
$count = 0;
$count++;
echo $count, "\n";Output
bool(true) bool(false) int(1) guest 10 apples 1
Prefer ===: it checks the type too and avoids surprises from automatic conversion.
Quick check
Which comparison also checks the type?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.