
Wikis & learning
Choose a label with a match expression
Map a small set of known values to labels. A match expression compares values strictly and produces a single result.
Map a small set of known values to labels. A match expression compares values strictly and produces a single result.
How it works
Keep a default arm when inputs can include an unfamiliar status. This makes the behavior of new statuses explicit.
PHP example
<?php
$state = 'queued';
$label = match ($state) {
'queued' => 'Waiting',
'done' => 'Complete',
default => 'Unknown status',
};
echo $label;Expected result
Waiting
Try a variation
Set the status to pending. Confirm that the default arm handles it.
Discussion
Sign in to participate.



