PHP Switch Statements ?


Switch statement is a control statement that allows us to choose only one choice among the many given choices. it is a control statement used to make a selection between many alternatives.

Syntax:-

switch(choice)
{
case value 1:
Block -1;
break;
case value 2:
Block – n;
break ;
default:
Block - d
}

Q.) W.A.P to design a calculator.
 <html>
 <body>
 <?php
 $ch=3;
 switch($ch)
 {
 case 1:
 echo “one”;
 break;
 case 2:
 echo “Two”;
 break;
 case 3:
 echo “Three”;
 break;
 default:
 echo “ only 1 to 3”;
 }
 ?>
 </body>
 </html>
Output
3
Three