ใช้คำสั่งเปลี่ยนเพื่อเลือกหนึ่งของบล็อกจำนวนมากของรหัสจะต้องถูกประหารชีวิต
ไวยากรณ์
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
default:
code to be executed if n is different from both label1 and label2;
}
ตัวอย่าง
<html>
<body>
<? PHP
$ x = 1;
สวิทช์ ($ x)
{
กรณีที่ 1:
echo "จำนวน 1";
แบ่ง;
กรณีที่ 2:
echo "จำนวน 2";
แบ่ง;
กรณีที่ 3:
echo "จำนวน 3";
แบ่ง;
เริ่มต้น:
echo "จำนวนไม่ระหว่าง 1 และ 3";
}
>?
</ body>
</ html>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น