kasus Switch Case

Posted by andi hasmiati In | 0 comments»
Pada contoh kali ini menampilkan daftar harga BBM di berbagai lokasi/ kota. Bahan bakar nya seperti pertamax, pertamax plus, dan pertamina dux. selain itu juga disertai harga bahan bakar yang berbeda disetiap kota. program ini menggunakan switch case dimana akan menampilkan harga bbm disatu kota yang telah dideklarasikan sebelumnya melalui variabel bahan ($ bahan ). 
berikut syntax selengkapnya. Anda dapat menyimpannya dengan nama bbm.php 

<style type="text/css">
<!--
.style1 {color: #990066}
.style3 {color: #9900CC}
.style4 {color: #FFFFFF}
.style6 {color: #999999}
.style7 {font-size: small; }
-->
</style>
<p class="style1">    &quot; Daftar harga BBM di SPBU   &quot;</p>
<table width="666" height="267" border="1">
  <tr>

    <th width="226" rowspan="2" bgcolor="#990000" scope="row"><div align="center" class="style4">lokasi </div></th>
    <th height="34" colspan="3" bgcolor="#990000" scope="row"><span class="style4">harga bahan bakar </span></th>
  </tr>
  <tr>
    <th width="161" height="33" bgcolor="#990000" scope="row"><div align="center" class="style6">pertamax</div></th>
    <td width="132" bgcolor="#990000"><div align="center" class="style6">pertamax plus </div></td>
    <td width="130" bgcolor="#990000"><div align="center" class="style6">pertamina dex </div></td>
  </tr>
  <tr>
    <th bgcolor="#CCCCFF" scope="row"><div align="center" class="style7">batam</div></th>
    <th bgcolor="#CCCCFF" scope="row"> <div align="center">-</div></th>
    <td bgcolor="#CCCCFF"><div align="right">Rp. 9800</div></td>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
  </tr>
  <tr>
    <th bgcolor="#CCCCFF" scope="row"><div align="center" class="style7">riau</div></th>
    <th bgcolor="#CCCCFF" scope="row"> <div align="center">-</div></th>
    <td bgcolor="#CCCCFF"><div align="right">Rp. 10950 </div></td>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
  </tr>
  <tr>
    <th bgcolor="#CCCCFF" scope="row"><div align="center" class="style7">jakarta</div></th>
    <th bgcolor="#CCCCFF" scope="row"><div align="right">Rp. 9550</div></th>
    <td bgcolor="#CCCCFF"><div align="right">Rp. 9850</div></td>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
  </tr>
  <tr>
    <th bgcolor="#CCCCFF" scope="row"><div align="center" class="style7">bangka</div></th>
    <th bgcolor="#CCCCFF" scope="row"><div align="right">Rp. 9900</div></th>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
  </tr>
  <tr>
    <th bgcolor="#CCCCFF" scope="row"><div align="center" class="style7">depok</div></th>
    <th bgcolor="#CCCCFF" scope="row"><div align="right">Rp. 9650</div></th>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
  </tr>
  <tr>
    <th bgcolor="#CCCCFF" scope="row"><div align="center" class="style7"><strong>FUEL  RETAIL MARKETING REGION III /IV/V</strong></div></th>
    <th bgcolor="#CCCCFF" scope="row"><div align="center">-</div></th>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
    <td bgcolor="#CCCCFF"><div align="right">Rp. 10300</div></td>
  </tr>
  <tr>
    <th height="42" bgcolor="#CCCCFF" scope="row"><div align="center" class="style7"><strong>FUEL  RETAIL MARKETING REGION VI (PPKB 5%)</strong></div></th>
    <th bgcolor="#CCCCFF" scope="row"> <div align="center">-</div></th>
    <td bgcolor="#CCCCFF"><div align="center">-</div></td>
    <td bgcolor="#CCCCFF"><div align="right">Rp. 12550</div></td>
  </tr>
</table>
<p><span class="style3">&gt;&gt;</span>
 
  <?php
  $bahan = "pertamax";
  switch($bahan)
  {
  case "pertamax" :
  $hrg = 9950;
  break;
 
  case "pertamax plus" :
  $hrg = 10950;
  break;
 
  case "pertamina dex" :
  $hrg = 10300;
  break;
 
  default :
  $hrg = 9900;
  break;
}

  echo  "maka harga pertamax dikota jakarta : Rp.$hrg";

?>
</p>

tampilan program nya :

0 comments:

Posting Komentar