How to use the Match Expression in PHP
In this lesson, we will see how to use the Match expression in PHP, since PHP 8.0.0 The match expression is available and you can use it as the switch expression the difference between the two expressions is that the match expression compares the type and the value === whereas switch compares only the value ==.
How to use
the example below shows how you can use the match expression:
$lang = "HTML";
$result = match($lang) {
'HTML' => 'HTML Technology',
'CSS' => ' CSS Styles',
'PHP' => 'Scripting Language',
'JS' => 'Javascript Language'
};
var_dump($result);
//string(15) "HTML Technology"