SWITCH is to substitute alternative command
structure with IF .. ELSE else rather than one that makes the program easier to
understand.
Syntax
:
switch(condition)
{
case costanta 1: statement1;
Break;
case costanta 2: statement2;
Break;
default : default statement;
}
Example :
1. Check
Month
$x=5;
Switch($x)
{
Case 1 : echo “January”;
Break;
Case 2 : echo “February”;
Break;
Case 3 : echo “March”;
Break;
Case 4 : echo “April”;
Break;
Case 5 : echo “May”;
Break;
Case 6 : echo “June”;
Break;
Case 7 : echo “July”;
Break;
Case 8 : echo “August”;
Break;
Case 9 : echo “September”;
Break;
Case 10 : echo “October”;
Break;
Case 11 : echo “November”;
Break;
Case 12 : echo “December”;
Break;
Default : echo “wrong
input”;
}
the result is May
No comments:
Post a Comment