PHP Else if / Elseif

PHP Else if / Elseif :– It is very comman to write code using conditional statement when we take any decision on the basis of our business logic.


PHP Else if / Elseif | Example

Here we discuss all possible outputs in detail which may produce by following example for learning of conditional statements in php .

  1. Following is an example for how to write an If..Else..If in php. In elseif condition loop controller looks for true condition ,once it got it will stop the execution after this point.
  2. If no condition is true then only else statement will give output for the program by default.

Note:–

You can use both elseif or else if with space or without space in your editor to program a script.Both will absolutely work .But one thing here is to be remember that is if you write colon after elseif condition then only elseif without space will work.

Example

<?php
$a=10;
$b=20;
if($a==$b){
echo "a is equal to b";
}

else if($a<$b){
echo "going into else if";;
}
elseif(){
echo "going into  second elseif";
}
else if():// compile error 
echo "will it be executed";

else{
echo "going into else";

}
?>


Advertisements

Add Comment

📖 Read More