Skip to content
AgileLogics
4 min read

Match Expressions

Prerequisites: Conditionals

PHP 8's match produces a value directly, using strict comparison, with no fall-through and no break needed:

$day = 3;
$name = match ($day) {
    1 => 'Monday',
    2 => 'Tuesday',
    3 => 'Wednesday',
    default => 'Unknown',
};
echo $name; // Wednesday

The older switch statement still exists and uses loose (==) comparison — match is preferred in modern PHP for exactly this reason.

Common mistakes

  • Forgetting match requires an exhaustive default (or every possible value covered) — an unmatched value throws UnhandledMatchError instead of silently doing nothing.