Site icon DataFlair

PHP Conditional Statements Part – 2

Program 1

<html>
    <head><title>PHP Condtional Operator Operators</title>
    <body>
     <center>
  
<?php
       $n=2;  // 1 to 5
       if($n==1)         
         echo " One";
      elseif($n==2)         
         echo " Two";
        elseif($n==3)         
         echo " Three";
        elseif($n==4)         
         echo " Four";
        elseif($n==5)         
         echo " Five";
        else
         echo " Invalid number";
       
     // Even odd  using if else
     // Find out grater between two number
     // Leap year or not

?>
</center>
</body>
</html>

Program 2

<html>
    <head><title>PHP Condtional Operator Operators</title>
    <body>
     <center>
<?php
    echo "<br><font color=red size=5>------------Menu---------------</font>";
    echo "<br><font color=Blue size=5>1.Addition</font>";
    echo "<br><font color=Blue size=5>2.Swap</font>";
    echo "<br><font color=Blue size=5>3.Max between two number</font>";
    echo "<br><font color=red size=5>---------------------------------</font>";
    $choice=6;
    if($choice==1)
    {
          $a=50;
          $b=20;
          $c=$a+$b;
          echo "<br>Addition of ".$a." and ".$b." is ".$c;
    }
    elseif($choice==2)
    {
        $a=50;
        $b=20;
        echo "<br>Before Sawping ".$a." and ".$b;
        $c=$a;
        $a=$b;
        $b=$c;
        echo "<br>After Sawping ".$a." and ".$b;
    }
    elseif($choice==3)
     echo "<br>Additioon Program";
    elseif($choice>3)
    echo "<br>Invalid choice";

?>
</center>
</body>
</html>

 

Exit mobile version