PHP Conditional Statements

Last updated: August 27, 2026.

Conditional statements choose behavior from runtime values. Use strict comparisons when automatic type conversion could be surprising.

<?php
declare(strict_types=1);
$score = 82;
if ($score >= 90) {
    $grade = 'A';
} elseif ($score >= 80) {
    $grade = 'B';
} else {
    $grade = 'C or below';
}
echo $grade;
<?php
$status = 'paid';
$label = match ($status) {
    'pending' => 'Waiting for payment',
    'paid' => 'Ready to fulfill',
    'cancelled' => 'Cancelled',
    default => 'Unknown status',
};

match uses strict comparison and returns a value. Use switch when fall-through is intentional.

admin

admin

Leave a Reply

Your email address will not be published.