COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
Switch(ñieàu kieän)
{
case
Value1
caâu
leänh1;
break;
case
Value2
caâu
leänh2;
break;
…
default:
caâu
leänh
default;
}
Break: duøng ñeå thoaùt ra khoûi switch khi thoaû moät case naøo ñoù trong switch,
default: khi khoâng coù baát kyø giaù trò naøo thoaûn trong caùc case thì giaù trò cuoái cuøng
laø defaule statement
Ví duï 3.10: Phaùt bieåu Switch
<HTML>
<HEAD>
<TITLE>::Welcome to PHP</TITLE>
</HEAD>
<BODY>
<h4>SWITCH Statement</h4>
<?php
$j=3;
$j=date("w");
$str="";
switch($j)
{
case 0:
$str="Today is Sunday";
break;
case 1:
$str="Today
is
Monday";
break;
case 2:
$str="Today
is
Tueday";
break;
case 3:
$str="Today
is
Wednesday";
break;
case 4:
$str="Today
is
Thursday";
3-9