mygomii

[PHP] #조건문 - switch/case 본문

PHP

[PHP] #조건문 - switch/case

mygomii 2018. 2. 19. 22:13
반응형

switch문


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
switch (n) {
    case label1:
        code to be executed if n=label1;
        break;
    case label2:
        code to be executed if n=label2;
        break;
    case label3:
        code to be executed if n=label3;
        break;
    ...
    default:
        code to be executed if n is different from all labels;
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
$favcolor = "red"// $favcolor 변수를 지정해줍니다.
 
switch ($favcolor) { //조건을 써줍니다.
    case "red"//red일때
        echo "Your favorite color is red!"//이 코드를 출력합니다.
        break//출력이 되면빠져나옵니다.
    case "blue":
        echo "Your favorite color is blue!";
        break;
    case "green":
        echo "Your favorite color is green!";
        break;
    default:
        echo "Your favorite color is neither red, blue, nor green!";
}
?>
cs



반응형

'PHP' 카테고리의 다른 글

[PHP] #배열 - Arrays  (1) 2018.02.20
[PHP] #반복문 - for/foreach  (1) 2018.02.20
[PHP] #조건문 - if/else/ifelse  (1) 2018.02.18
[PHP] #print  (0) 2018.02.17
[PHP] #echo  (0) 2018.02.17