Originally published on zero2php.dev — part of the Zero to PHP course. View this lesson on the original site.
Comparisons and logic
You already used arithmetic. Add comparisons and logic:
- Comparisons:
<,>,<=,>=,==,!=,===,!== - Logic:
&&,||,! - Ternary (light):
$x ? 'yes' : 'no'
Example
<?php
declare(strict_types=1);
$score = 10;
var_dump($score > 0 && $score < 100);
Precedence
Precedence trips people up—when in doubt, add parentheses to make intent obvious.
Exercise
echo 1 if 10 === 10 is true, else 0 (use a comparison and output a single character).
From Zero to PHP — PHP foundations: environment, syntax, and values