switch example

SwitchExample.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>switch in php example</title>
</head>

<body>
 <h2 style="color:pink;">switch in php example</h2>
 <div style="color:#aaf; text-align:left; padding-top:12px;">
 <?php
  $i = 1;
  
  if ($i == 0) 
  {
   echo "i equals 0";
  } 
  elseif ($i == 1) 
  {
   echo "i equals 1";
  } 
  elseif ($i == 2) 
  {
   echo "i equals 2";
  }
   /*
  |------------------------------------------------------------
  | comparing same variable $i with many different values.
  |------------------------------------------------------------
  */
  
  echo "<br>";
  echo "<br>";
  
  switch ($i) 
  {
   case 0:
    echo "i equals 0";
    break;
   case 1:
    echo "i equals 1";
    break;
   case 2:
    echo "i equals 2";
    break;
  }
   /*
  |------------------------------------------------------------
  | does the same but faster.
  |------------------------------------------------------------
  */
 ?>
 </div>
</body>
</html>


No comments:

Post a Comment

leave your comments here..