Files
developer-roadmap/roadmaps/php/content/match@3gNzX-bw2iqur7U7-_W38.md
Arik Chakma 274082fd77 feat: clean roadmap content and sync scripts (#10181)
* refactor: clean to roadmap content

* refactor: move shared helpers into scripts/lib
2026-07-28 05:45:17 +06:00

882 B

match

Match expressions are an integral feature of PHP, introduced in PHP 8.0 as an alternative to the switch statement. Compared to the switch statement, match expressions are safer since they don't require break statements and are more concise. The match expression can be an excellent tool for pattern matching. Here's an example:

$message = match ($statusCode) {
  200, 300 => 'OK',
  400 => 'error',
  default => 'unknown status code',
};

In this code, based on the value of $statusCode, the match expression assigns a specific text to the $message. If $statusCode is not 200, 300, or 400, the default case applies. After running the code, the $message variable contains the result of the match expression.

Visit the following resources to learn more: