While switch works, it uses loose comparison (==) and requires break; on every case to avoid accidental fall-through bugs. PHP 8's match expression is much safer:
- Uses strict comparison (
===) - No
break;needed - Returns a value directly
- Throws an
UnhandledMatchErrorif no branch matches (unless you includedefault)
ADVERTISEMENT