Skip to content
Justice Tech School

match Expression

match returns a value, compares strictly and throws if nothing matches unless you add default.

Example
$code = 404;
echo match ($code) {
    200 => "OK",
    404, 410 => "Gone",
    default => "Other",
};

Result

Gone

Exercise

Fallback arm.

 => "x"

Quiz Test

How does match compare?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.