Switch Statement In PHP-
..............................................................................................................................................



It is used to create option based or choice-based program.we can choose or select a particular option in options set.


Switch contains multiple cases to define multiple options.

switch(option)       //option==optionvalue
{
         case optionvalue:
              optionstatement;
              break;
        case optionvalue:
              optionstatement;
              break;
        case optionvalue:
              optionstatement;
              break;

       default:
          statement;
          break;

}


WAP to display "yes","no" and "cancel"?

<?php

$op='L';
$option = (ord($op)>=65 && ord($op)<=91)?chr(ord($op)+32):$op;
switch($option)
{
case 'y':
echo "YES";
break;
case 'n':
echo "NO";
break;
case 'c':
echo "CANCEL";
break;
default:
echo "INVALID INPUT";
break;
}





?>

ASSIGNMENT:-

1)  WAP to check the greater number using Switch?

2)  WAP to check even or odd using Switch?

3) WAP to check vowel and Consonant using Switch?

4)  WAP to calculate addition, subtraction, multiplication, and division when user press +,-,*, and / Symbol.






Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post