The PHP switch-case statement is an alternative to the if-elseif-else statement. PHP switch statement is used to execute one statement from multiple conditions.
switch(…){…} is the control structure block code
case value : case… are the blocks of code to be executed depending on the value of the condition
default : is the block of code to be executed when no value matches with the condition
<!DOCTYPE html>
<html>
<head>
<title>PHP Switch Statement</title>
</head>
<body>
<?php
$today = date("D");
switch($today){
case "Mon":
echo "Today is Monday.";
break;
case "Tue":
echo "Today is Tuesday.";
break;
case "Wed":
echo "Today is Wednesday.";
break;
case "Thu":
echo "Today is Thursday.";
break;
case "Fri":
echo "Today is Friday.";
break;
case "Sat":
echo "Today is Saturday.";
break;
case "Sun":
echo "Today is Sunday.";
break;
default:
echo "No information available for that day.";
break;
}
?>
</body>
</html>