The match expression

The match expression compares a value to several cases using strict comparison and returns the result of the matching case. Unlike switch, it needs no break and throws an UnhandledMatchError if no case matches and there is no default.

Example

$libelle = match ($code) {
  200 => 'OK',
  404 => 'Introuvable',
  default => 'Autre',
};

Related concepts

The whole glossary