Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

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.
$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.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments