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.

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


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 :

- 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 :

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

- 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).

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