PHP 8 · Types and functions
Use match instead of switch
Match with strict comparison. It returns a value and throws if nothing matches.
$label = match ($status) {
Status::Draft => 'Draft',
Status::Published => 'Live',
};
PHP 8 · Types and functions
Match with strict comparison. It returns a value and throws if nothing matches.
$label = match ($status) {
Status::Draft => 'Draft',
Status::Published => 'Live',
};
Was this page helpful?