php tutorial - PHP if elseif else Condition - php programming - learn php - php code - php script



  • The if....elseif...else statement executes different codes for more than two conditions.
  • The if...elseif...else is a special statement that is used to combine multiple if...else statements.
 If Elseif Statement

Learn PHP - PHP tutorial - If Elseif Statement - PHP examples - PHP programs

php programming Syntax :

if (condition) 
{
   condition statement is true;
}
elseif (condition) 
{
    condition statement is true;
} 
else 
{
    condition statement is false;
}
click below button to copy the code. php tutorial - team

php - php 7 - php tutorial - php framework tutorial - php examples - php sample code - php basics - php web development - php components - php project - php technology  - learn php - php online - php programming - php program - php code - html code - embedded php in html - web server  - php syntax - php function - php if  elseif else condition
php - php 7 - php tutorial - php framework tutorial - php examples - php sample code - php basics - php web development - php components - php project - php technology  - learn php - php online - php programming - php program - php code - html code - embedded php in html - web server  - php syntax - php function - php if  elseif else condition

learn php Sample Code : sample php program

<!DOCTYPE html>
<html>
    <head>
        <title>if-elseif-else-Condition</title>
    </head>
    <body>
        <?php
            $t = date("Y");
            if ($t == "2015") 
            {
                echo "You are in 2016 ";
            } 
            elseif ($t > "2015") 
            {
                echo "You are in 2016";
            } 
            else 
            {
                echo "Wait for 2017 ";
            }
        ?>
    </body>
</html>
click below button to copy the code. php tutorial - team

php for beginners Code Explanation :

Code Explanation for If elseif else Condition In PHP

  1. In this code $t = date("Y"); specifies a variable $t that defines year.
  2. Here is the “if-elseif-else” statement where, the If condition executes the statements based on the true and false condition. Similarly, if the condition is false it executes the other elseif & if statements.

php coding Sample Output :

output1 for If elseif else Condition In PHP

  1. Echo statements prints “You are in 2015” statement based on the execution of “IF Condition” which executes the condition to be true.

output2 for If elseif else Condition In PHP

  1. Echo statements prints “You are in 2016” statement based on the execution of “elseif Condition” which executes the condition. (where the if condition is false).

output3 for If elseif else Condition In PHP

  1. Echo statements prints “Wait for 2017” statement based on the execution of “else Condition” which executes the condition. (where the elseif condition is false).


Related Searches to php ifelseif else Condition