PHP Switch

Posted On: March 5, 2016

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!”;
}
?>

Also Read :   PHP Variables
X
Subscribe to our newsletter
Subscribe to our newsletter today to receive updates on the latest news and offers.
100% Privacy. No spam guaranteed
webe tutorial
Menu