1switch (fruit) {
2 case apple:
3 code to be executed if fruit=apple;
4 break;
5 case banana:
6 code to be executed if fruit=banana;
7 break;
8 ...
9 default:
10 code to be executed if fruit is different from all fruits;
11}
1$age=20;
2switch ($age) {
3 case 19:
4 echo "Age is 18";
5 break;
6 case 20:
7 echo "Age is 20";
8 break;
9 case 21:
10 echo "Age is 21";
11 break;
12}
1$fruit = "apple";
2switch ($fruit) {
3 case "apple":
4 echo "doctor";
5 break;
6 case "banana":
7 echo "monkey";
8 break;
9 default:
10 echo "things";
11}//doctor
1switch ($element) {
2 case 0:
3 echo "i es igual a 0";
4 break;
5 case 1:
6 echo "i es igual a 1";
7 break;
8 case 2:
9 echo "i es igual a 2";
10 break;
11}
1<?php
2
3$fav_food = "burger";
4
5switch($fav_food)
6{
7 case "pavbhaji":
8 echo "My favourite food is pavbhaji";
9 break;
10
11 case "dhosa":
12 echo "My favourite food is dhosa";
13 break;
14
15 case "dabeli":
16 echo "My favourite food is dabeli";
17 break;
18
19 case "burger":
20 echo "my favourite food is burger";
21 break;
22
23 default:
24 echo "I am foody..";
25 break;
26}
27?>
1<?php
2switch ($i) {
3 case "apple":
4 echo "i is apple";
5 break;
6 case "bar":
7 echo "i is bar";
8 break;
9 case "cake":
10 echo "i is cake";
11 break;
12}
13?>