Separate multiple comma-delimited values within a single match expression arm to group identical execution branches.
When multiple inputs share the exact same output branch in a match expression, list the values separated by commas in a single match arm instead of repeating arms.
$status = 'processing';
$label = match ($status) {
'pending', 'processing', 'queued' => 'In Progress',
'completed', 'delivered' => 'Successful',
'failed', 'cancelled' => 'Unsuccessful',
default => 'Unknown Status',
};
- Groups multiple matching conditions using comma-separated expressions
- Eliminates duplicate result assignments across identical logic arms
- Evaluates using strict identity comparison (===)
Related Tips
View all tips →
PHP
Syntax
Simplify Class Instantiation with Constructor Property Promotion
Combine property declarations and constructor parameter assignments in PHP 8 for concise class definitions.
READ
>
PHP
Syntax
Unpack Arrays with Spread Syntax in PHP 8.1
Use array unpacking (...) inside square bracket array literals for string-keyed and indexed array merging.
READ
>