devnotes.

Conditionals: if, switch, match

if ($age >= 18) {
    echo "Adult";
} elseif ($age >= 13) {
    echo "Teenager";
} else {
    echo "Child";
}

// Ternary shorthand
$status = $age >= 18 ? 'adult' : 'minor';
// Null-safe shorthand when checking the same variable
$name = $username ?: 'Guest'; // uses $username if truthy, else 'Guest'

switch compares a value against several cases (using loose == comparison, and 'falls through' without break):

switch ($role) {
    case 'admin':
        echo "Full access";
        break;
    case 'editor':
        echo "Can edit content";
        break;
    default:
        echo "Read-only access";
}

match (PHP 8.0+) is a modern, expression-based alternative: it uses strict comparison, has no fallthrough, requires no break, and returns a value directly:

$label = match ($role) {
    'admin', 'superadmin' => 'Full access', // multiple conditions per arm
    'editor' => 'Can edit content',
    default => 'Read-only access',
};

Most modern PHP code prefers match over switch for value-mapping logic, because it's more concise and avoids fallthrough bugs.

PHP if, switch, and match Statements | DevNotes