Home Tutorial Php Phpbasics Tutorial PHP ElseIf Construct

 
 

PHP ElseIf Construct
Posted on: March 25, 2010 at 12:00 AM
In this tutorial we will study about elseif in PHP. How to write elseif body part, what are the constraints to use etc. Aare discussed in this tutorial. Examples in this tutorial will make it more clear.

Elseif construct:

Combination of else and if is known as elseif or else if. It is executed only when the if portion is false, but unlike else, we can put any condition with it. The conditions will be check only when the if part is false.

In a program there could be several 'elseif' block, we can write nested 'elseif' also, the elseif statement will execute only if the preceding if and elseif statements are false.

Example:

<?php

$a=13;

$b=44;

$c=142;

if($a>$b)

{

if($a>$c)echo '$a is greatest';

}

elseif($b>$c) echo '$b is greatest';

else echo '$c is greatest';

?>

 

Output:

$c is greatest

Example:

<?php

$a=1333;

$b=144;

$c=142;

if($a>$b && $a>$c) echo '$a is greatest';

elseif($b>$c && $b>$a) echo '$b is greatest';

else echo '$c is greatest';

?>

 

Output:

$a is greatest

Related Tags for PHP ElseIf Construct:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.