ElseIf Statement in PHP - If More Than One Conditions is True


If there is a posibilities that several condition is true, then use elseif statement. Below is syntax for elseif statement in PHP:-

if (condition)
Code1 with posible true condition;
elseif (condition)
Code2 with posible true condition;
else
code with posible true condition;

Example:-

Below example will output “Have a nice weekend!” if the current day is Friday, and “Have a nice Sunday!” if current day is Sunday. Otherwise it will output “Have a nice day!”.

<html>
           <body>
          <?php
                    $d=date("D");
                    if ($d=="Fri")
                           echo "Have a nice weekend!";
                    elseif ($d=="Sun")
                           echo "Have a nice Sunday!";
                    else
                           echo "Have a nice day!";
          ?>
         </body>
</html>

ElseIf Statement in PHP
ElseIf Statement in PHP


Related Posts:

0 comments:

Post a Comment

Recent Post

All Loop Types in PHP

Loops are used to execute a block of codes until a certain condition is met. The main benefit of using a loop is to save the time and effor...

Popular Posts