The PHP Switch Statement

Use the switch statement to select one of many blocks of code to be executed.
Syntax:
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
default:
code to be executed if n is different from both label1 and label2;
}

sample code is about the switch dice program:

<?php
$roll = rand(1,4);
print “You rolled a $roll”;
print “<br>”;

switch ($roll)
{
case 1:
$romValue = “I”;
break;
case 2:
$romValue = “II”;
break;
case 3:
$romValue = “III”;
break;
default:
print “This is an illegal die!”;
} // end switch
print “<img src = die$roll.jpg>”;
print “<br>”;
print “In Roman numerals, that’s $romValue”;
?>
<br>
Refresh this page in the browser to roll another die.