xxxxxxxxxx
// Using switch statement
$fruit = "apple";
switch ($fruit) {
case "apple":
echo "The fruit is an apple.";
break;
case "banana":
echo "The fruit is a banana.";
break;
default:
echo "The fruit is unknown.";
break;
}
echo "\n";
// Using match expression (PHP 8+)
$fruit = "apple";
echo match($fruit) {
"apple" => "The fruit is an apple.",
"banana" => "The fruit is a banana.",
default => "The fruit is unknown.",
};