Home Tutorial Php Phpbasics Tutorial PHP Else Construct

 
 

Share on Google+Share on Google+
PHP Else Construct
Posted on: March 25, 2010 at 12:00 AM
Advertisement
In this tutorial we will study about else in PHP. How to write else body part, what are the constraints to use else are discussed in this tutorial. Examples in this tutorial will make it more clear.

Else Construct:

Else construct is generally used when a previous condition does not met, it means that we place the else construct after if statement and if  'if statement' does not met, then the else part will be executed.

We can not put condition with else part, as the name implies that we use else part only when if statement is false, it is also true that we can not use else part alone.

Example:

<?php

$a=133;

$b=144;

if($a>$b)echo "\$a is greater";

else echo "\$b is greater";

?>

Output:

$b is greater

Another way to write if/else block is shown below:

Example:

<?php

$a=133;

$b=44;

if($a>$b):

echo "\$a is greater";

else: echo "\$b is greater";

endif;

?>

Output:

$a is greater

Advertisement

Related Tags for PHP Else 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