PHP match Expression Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report The PHP match expression is used for the identity check of a value. It is similar to the switch statement i.e. it matches the expression with its alternative values. The match expressions are available in PHP 8.0.0. The match expression compares the value using a strict comparison operator (===) whereas the switch statement uses a loose comparison operator (==). Syntax: return_value = match(expr) { key1 => val1, key2 => val2, ... } Note: The match expression must be ended with semicolons. Example 1: The following code demonstrates the match expression in PHP. PHP <?php $sub = 'PHP'; $val = match ($sub) { 'HTML' => 'HTML Course', 'CSS' => 'CSS Course', 'PHP' => 'PHP Course', 'JavaScript' => 'JS Course', 'WebDev' => 'Complete Web Development' }; var_dump($val); ?> Output: string(10) "PHP Course" Example 2: The following code is another example of a PHP match expression. PHP <?php $marks = 78; $res = match (true) { $marks < 33 => 'Fail', $marks < 45 => 'Third Division', $marks < 60 => 'Second Division', $marks < 75 => 'First Division', $marks <= 100 => 'Distinction' }; var_dump($res); ?> Output: string(11) "Distinction" Reference: https://www.php.net/manual/en/control-structures.match.php Create Quiz Comment V vkash8574 Follow 1 Improve V vkash8574 Follow 1 Improve Article Tags : Web Technologies PHP PHP-Control-Statement Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like