
Else-If Statement
Syntax
if(condition_1) | |
{ | |
statement_1_Block; | |
} | |
elseif(condition_2) | |
{ | |
statement_2_Block; | |
} | |
elseif(condition_3) | |
{ | |
statement_3_Block; | |
} | |
elseif(condition_n) | |
{ | |
statement_n_Block; | |
} | |
else | |
statement_x; |
Sample Program
<?php | |
if(10>5) | |
{ | |
echo "IF condition is True."; | |
} | |
elseif(5<7) | |
{ | |
echo "First elseif condition is True."; | |
} | |
elseif(6<7) | |
{ | |
echo "Second elseif condition is True."; | |
} | |
elseif(5>2) | |
{ | |
echo "Third elseif condition is True."; | |
} | |
else | |
echo "All Conditions are False." ; | |
?> |
Output

In the above program, if the First condition is false then it will check the third condition, if itβs true then print it else check next condition and so on.
Ternary or Conditional Operator.
It works similar to the else-if statement. In this Operator, if the condition is true then it returns First-Expression else Second-expression.
Syntax
Variable = Condition ? Expression1 : Expression2
For Example:- $a = (5>1) ? βGreaterβ : βLessβ ;
Sample program
<?php
$a = (5>1) ? βGreaterβ : βLessβ ;
echo $a;
?>
Output

Switch Statement
It checks several constant values for an expression.
Syntax
switch(expression){
case expression1:
block of statements;
break;
case expression2:
block of statements;
break;
case expression-n:
block of statements;
break;
default:
block of statements;
}
Sample Program
<?php | |
$date = 19; | |
switch ($date) | |
{ | |
case 10: | |
echo "Maths"; | |
break; | |
case 12: | |
echo "Science"; | |
break; | |
case 15: | |
echo "Social-Science"; | |
break; | |
case 17: | |
echo "English"; | |
break; | |
case 19: | |
echo "Hindi"; | |
break; | |
case 22: | |
echo "Java Programming"; | |
break; | |
case 25: | |
echo "PHP"; | |
break; | |
default: | |
echo "No Exam"; | |
} | |
?> |
Output





With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.