Thursday 1 December 2016

Chapter 5(PHP) Switch Statement And How to make Links From which we can go from one program to another

Switch Statement 

             Switch statement is used to run a particular block of the program .we write many cases in switch statement and the case which get matched with the value which we assign to user define variable will get executed.

PROGRAM

<html>
<body>

<?php
$x=2;
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> 

EXPLANATION
 Here we take a user define variable $x and assign value to it after that we use switch statement like
 switch ($x) after that we make different types of cases in switch statement like
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";

as we know we assign value 2 to the variable x and it matches with case 2 because 2 matches with 2 so case 2 will get executed.

break; is used to terminate the program and if we cant use break statement than other blocks below the matching case will also get executed.

OUTPUT



HOW TO MAKE LINKS FROM WHICH WE CAN GO FROM ONE PROGRAM TO ANOTHER
SAME METHOD IS USED IN WEBSITES

PROGRAM

<html>
<body>

<a href="p1.php">Home</a>
<a href="p4.php">Tutorials</a>



</body>
</html> 

EXPLANATION

This code is written in html first we have to declare <html> tag after that we have to declare body tag like <body> after that we have to write hypertext link which we can write as
<a href="p1.php">Home</a>
<a href="p4.php">Tutorials</a>

<a href="p1.php"> it means go to p1.php program you can also write any link which you want to go.
Home is the name of link which on clicking it will open p1.php program 
</a> closing hypertext link it is necessary to close.
and in last we close body tag and html tag like </body> </html> 
all the code should be written in body tag and after that body tag and html will be closed.

No comments:

Post a Comment