Home Tutorial Php Phpbasics IF - PHP If and else Statement

 
 

Share on Google+Share on Google+
IF - PHP If and else Statement
Posted on: October 27, 2009 at 12:00 AM
Advertisement
PHP IF Statement is a conditional statement that gives the opportunity to choose between two values. It can also be used to validate the program.

IF - PHP If and else Statement in PHP

“IF” is a conditional statement that gives the opportunity to choose between two values. It can also be used to validate the program. Login applications are good example of if else statement. 

Apart from PHP there are many more programming languages that too uses if else statement as a conditional operator.

Lets take an example to understand it in better way... suppose we have only one item in the database and if the user chooses the same item he can shop else a message will given to user that “there is no such item available”.

Code:

<?php
$item=1;
if ($item==1)
  echo "You can buy!";
else
  echo "There is no such item available.";
?>

This was just a simple example that has used if statement only one time in the whole code. But there could be situation like you wanted to use it more then once. PHP also support this feature, you can use if statement in your program as many times as you want.

Syntax of PHP if else if Statement

if (condition)
  Execute if condition is true;

elseif (condition)
Executed if second condition is true;

else
In case both conditions are false;

Advertisement

Related Tags for IF - PHP If and else Statement:


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: October 27, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com