PHP If..Else.. Statement

by Anu Gaba 15-Jan-16

0 1168


The conditional statements are used to take decision based on the different situations. You can use these statements in your code to make your decisions. Like other programming language, PHP also offers you to write these statements to perform different actions based on the results of a logical or comparative test conditions at execution time. PHP supports following decision making statements

PHP Conditional Statements...
Conditional statements are used to take actions based on different conditions. In PHP these are following conditional statements:

If Statement : Execute code when one condition is true, if condition is false than code will not be execute.
If.else statement : Execute code  if condition is true and another code if that condition is false
If .. elseif .. else statement : its use for more than two conditions.

Syntax:
<?php
if (condition) {
code to be executed if condition is true;
}
?>

Example:

<?php
$t = 50;
if ($t < 20) {
echo "Right Answer";
}
?>

Example:

<?php
$d = 10;
if ($d == 20)
echo "if condition is true";
elseif ($d == 10)
echo "elseif condition is true";
else
echo "elseif condition is true";

?>

Result: elseif condition is true


Share:


Comments

    No Comments Yet.

Leave a Reply