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](https://wikitechy.com/php/img/php-images/if-elseif-statement.gif)
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](https://wikitechy.com/php/img/php-images/php-if-elseif-else-statement.png)
![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](https://wikitechy.com/php/img/php-images/if-elseif-if-statement.png)
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 Code Explanation for If elseif else Condition In PHP](https://wikitechy.com/php/img/php-images/code-explanation-php-if-elseif-else-condition.png)
- In this code $t = date("Y"); specifies a variable $t that defines year.
- 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 output1 for If elseif else Condition In PHP](https://wikitechy.com/php/img/php-images/output1-for-php-if-elseif-else-condition.png)
- 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 output2 for If elseif else Condition In PHP](https://wikitechy.com/php/img/php-images/output2-for-php-if-elseif-else-condition.png)
- 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 output3 for If elseif else Condition In PHP](https://wikitechy.com/php/img/php-images/output3-for-php-if-elseif-else-condition.png)
- Echo statements prints “Wait for 2017” statement based on the execution of “else Condition” which executes the condition. (where the elseif condition is false).