codegurukool.com · Free coding tutorials & online compiler

Home › PHP Tutorial › PHP switch and match

PHP switch and match

Pick one of many branches.

match (PHP 8) is a stricter, shorter switch. It returns a value and uses strict comparison, so no break is needed.

Example code

<?php
$day = 3;
echo match($day) {
  1 => "Mon",
  2 => "Tue",
  3 => "Wed",
  default => "Other",
};
?>

Run this code in the online editor

← PHP if...else...elseifPHP loops →