Match Multiple Values in a Single Match Arm in PHP

Punyapal Shah
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 (===)
Tags: #PHP #Control Flow #Syntax
Share on X

// Found an issue or want to contribute a tip? github.com/MrPunyapal/tips