forked from chetanupare/php-programs-for-beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp-switch.php
More file actions
40 lines (33 loc) · 691 Bytes
/
php-switch.php
File metadata and controls
40 lines (33 loc) · 691 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
<!-- Switch Statement In Php To Execute code from one block
Syntax:
switch (x)
{
case 1:
code to be executed if x=1;
break;
case 2:
code to be executed if x=2;
break;
case 3:
code to be executed if x=3;
break;
default:
code to be executed if n is different from all labels;
}
-->
<?php
$x=2;
switch ($x) { //checking x = cases below
case '1': //not matched
echo "x=1";
break;
case '2': //matched the x=2 executing statement
echo "x=2"; //output value
break; //break to get switch case execution to the end
case '3':
echo "x=3";
default:
echo "value of x is none of this 1,2,3";
break;
}
?>