-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathswitch_exsample.php
More file actions
59 lines (49 loc) · 979 Bytes
/
switch_exsample.php
File metadata and controls
59 lines (49 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
//initialize with a random integer within range
$diceNumber = mt_rand(1, 6);
//initialize
$numText = "";
//calling switch statement
switch($diceNumber)
{
case 1:
$numText = "One";
break;
case 2:
$numText = "Two";
break;
case 3:
case 4:
// case 3 and 4 will go to this line
$numText = "Three or Four";
break;
case 5:
$numText = "Five";
echo $numText;
// break; //without specify break or return it will continue execute to next case.
case 6:
$numText = "Six";
echo $numText;
break;
default:
$numText = "unknown";
}
//display result
echo 'Dice show number '.$numText.'.';
/*
if case is 1
> Dice show number One.
if case is 2
> Dice show number Two.
if case is 3
> Dice show number Three or Four.
if case is 4
> Dice show number Three or Four.
if case is 5
> FiveSixDice show number Six.
if case is 6
> SixDice show number Six.
if none of the above
> Dice show number unknown.
*/
?>