Bab 7
Switch
Switch digunakan untuk melakukan suatu aksi dari beberapa
aksi yang berbeda berdasarkan pada satu atau lebih kondisi yang berbeda.
Sintaks
switch (expression)
{
case label1:
code to be
executed if expression = label1;
break;
case label2:
code to be
executed if expression = label2;
break;
default:
code to be
executed
if expression is
different
from both label1
and label2;
}
|
Program7-1.php
<html>
<body>
<?php
switch ($x)
{
case 1:
echo
"Number 1";
break;
case 2:
echo
"Number 2";
break;
case 3:
echo
"Number 3";
break;
default:
echo "No
number between 1 and 3";}
?>
</body>
</html>
|
0 comments:
Post a Comment