The new match is similar to the switch and has the following features:
- The match is an expression, meaning its result can be stored in a variable or returned.
- Match branches only support single-line expressions and do not need a break; statement.
- The match does strict comparisons.
<?php
$message = match($var) {
'a' => 'The variable was a',
'b' => 'The variable was b',
'c', 'd' => 'The variable was c or d',
default => 'The variable was something else',
};
print $message;
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.