Home Tutorial Php Phpbasics Tutorial PHP ElseIf Construct

 
 

PHP ElseIf Construct
Posted on: March 25, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for PHP ElseIf Construct:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 25, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com