The switch is used to execute dissimilar actions based on dissimilar conditions.
Syntax:-
switch (n) {
case label1:
Execution code if n=label1;
break;
case label2:
Execution code if n=label2;
break;
case label3:
Execution code if n=label3;
break;

default:
Execution code if n is different from all labels;
}
Example:-
<?php
$week = “monday”;

switch ($week) {
case “sunday”:
echo “Today is Sunday!”;
break;
case “Monday”:
echo “Today is monday!”;
break;
case “Tuesday”:
echo “today is Tuesday!”;
break;
default:
echo ” Today is Wednesday!”;
}
?>

Categories: PHP

0 thoughts on “PHP Switch”

Leave a Reply