0

Switch

Posted by Jujur Sitanggang on 5:13 AM


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
$d=date("D");
switch ($d)
{
case “Mon”:
  echo “Monday”;
  break;
case “Tue”:
  echo “Tuesday”;
  break;
case “Wed”:
  echo “Wednesday”;
break;
case “Thu”:
  echo “Thurday”;
  break;
case “Fri”:
  echo “Friday”;
  break;
case “Sat”:
  echo “Saturday”;
  break;
case “Sun”:
  echo “Sunday”;
  break;
default:
  echo "No day else";
}
?>
</body>
</html>



0 Comments

Copyright Jujur Soaloon Sitangang Lipan All rights reserved. Theme by Sitanggang. | Bloggerized by Soalparna.