PHP If-Else Control Statement !!
PHP If-else is a one type of control statement.we have many control statements for control the flow of source code.
Control Statements :
- If - else
- For Loop
- While & Do-while Loop
- Break
- Continue
- Switch
In this article we discussed about If-else statement in brief with example.
Types Of Statements :
If Statements
This if statements use for check a specific condition.
if condition is true, then code of if block will execute otherwise not.
There are two possibilities :
1) condition : True then code of if block execute.
2) condition : False then if block will not execute.
Syntax :
if ( condition)
{
code of block
}
Program :
Write PHP Program For Check the given strings are same.
Output :
x and y strings are same
Work flow :
1) take x = khush & y = khush
2) check x = y is true or false
3) here x = y is true then it execute code of if statement.
If - Else Statements
This If else block used when we have to execute some code in case of condition is false.
if condition is true then code of if block will execute otherwise code of else block will execute.
Syntax :
if ( condition )
{
code of if block ## execute when condition is true
}
else
{
code of else block ## execute when condition is false
}
Program :
Output :
number is odd
Work flow :
1) Here, x is 3
2) 3 % 2 ==1 so, condition is false
3) go to else statement and print "number is odd"
if-elseif-else Statement
elseif statement used when we have to check more than one condition.
elseif keyword is used for more condition.
we can put any number of elseif statements between if and else statements.
first if statement checks if it is true then if block will execute, otherwise it go to the elseif statement if it is true then execute code of elseif block and if both are false then else part executed.
Syntax :
if ( condition )
{
code of if block ## execute when if is true
}
elseif ( condition )
{
code of elseif block ## execute when if is false and elseif is true
else
{
code of else block ## executes when if and elseif both are false
}
Program :
Output :
b is greater
Work flow :
1) check a > b means 10 > 15 it is not true.
2) go to the elseif statement check b > a means 15 > 10,
yes condition is true then execute elseif block.
More Programs Of If, If-else, If-elseif-else Control statements :
Program :
<html>
<head>
<?php
$a = "8" ;
if ($a<10)
print "a is less than 10";
?>
</head>
</html>
Output :
a is less than 10
<html>
<head>
<?php
$a = "8" ;
if ($a<10)
print "a is less than 10";
?>
</head>
</html>
Output :
a is less than 10
Program :
<html>
<head>
<?php
$a = "-10";
if($a>0)
{
print "a is negative" ;
}
else
{
print "a is positive" ;
}
?>
</head>
</html>
Output :
a is negative
Program :
<html>
<head>
<?php
$x = 1;
$y = 2;
if ($x != $y)
$x = $x * $y;
else
$x = $x + $y;
echo $x;
?>
</head>
</html>
Output :
3
Program :
<html>
<body>
<?php
$d = date("D");
if ($d == "Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>
</body>
</html>
Output :
have a nice weekend!
In next article we will discussed about other control statements in detail so keep join us for get more interesting PHP tutorials.
You Can Also Search For :
- PHP Variables
- Different Data-Types In PHP
- Constants Of PHP
- PHP If-Else Control Statement
- PHP - XML Introduction !!
- PHP Different Frame Works !!
- PHP Break, Continue Control Statement !!
- PHP Form With GET And POST Method !!
- PHP For Loop Control Statement !!
Mesothelioma Survival Rates , Mesothelioma Attorneys California , Seattle Mesothelioma Lawyer , Mesothelioma Suit , Mesothelioma Claim , Wisconsin Mesothelioma Attorney , Mesothelioma Attorney illinois , Mesothelioma Trial Attorney ,Houston Mesothelioma Attorney , Mesothelioma Lawyer Dallas , New York Mesothelioma Law Firm,Mesothelioma Lawyer Asbestos Cancer Lawsuit , Mesothelioma Lawyers San Diego,Mesothelioma Litigation , Mesothelioma Attorney Assistance , Mesothelioma Lawyer Asbestos Cancer Lawsuit , Mesothelioma Lawyer Chicago , New York Mesothelioma Law Firm ,
Houston Mesothelioma Attorney , Mesothelioma Lawyer Dallas , Mesothelioma Care , Mesothelioma Trial Attorney , Mesothelioma Lawyer Texas , Lawsuit Mesothelioma , Truck Accident Attorney Los Angeles ,Asbestos Exposure Lawyers , Mesothelioma Cases , Emergency Response Plan ppt , Mesothelioma Lawyers San Diego , Asbestos Mesothelioma Lawsuit , Tennessee Mesothelioma Lawyer , Meso Lawyer , Mesothelioma Settlements Amounts , Mesothelioma Law Firms , New Mexico Mesothelioma Lawyer , Accident Attorneys Orange County , Mesothelioma Lawsuit ,Personal Injury Accident Lawyer , Purchase Structured Settlements , Firm Law Mesothelioma , Car Accident Lawyers Los Angeles , Mesothelioma Attorneys , Structured Settlement Company , Auto Accident Lawyer San Francisco , Mesotheolima , Los Angeles Motorcycle Accident Lawyer
Mesothelioma , Mesothelioma Lawyer Virginia , Seattle Mesothelioma Lawyer , Mesothelioma Attorney illinois , Mesothelioma Drug , Mesothelioma Attorney DirectoryMesothelioma Settlements , Mesothelioma Help , Mesothelioma ct , Mesothelioma Attorney Florida , Washington Mesothelioma Attorney , Best Mesothelioma Lawyers , Diagnosed With Mesothelioma , Mesothelioma Settlement Amounts , Mesothelioma Personal Injury Lawyers , Mesothelioma Compensation , Attorney Lawyer Mesothelioma ,Colorado Mesothelioma Lawyers,Mesothelioma Lawsuits , Mesothelioma Claims , Average Mesothelioma Settlement , Average Mesothelioma Settlement , Mesothelioma Law Suit , Alabama Mesothelioma Lawyer , alabama Mesothelioma Lawyer , utah mesothelioma lawyer , Dallas Mesothelioma Lawyer , Mesothelioma Attorney California , Mesothelioma Lawyer California ,Mesothelioma Survival Rates ,
Mesothelioma Attorneys California, Wisconsin Mesothelioma Attorney Mesotheliama , Mesothelioma Lawyer Virginia , Seattle Mesothelioma Lawyer , Mesothelioma Attorney illinois, Mesothelioma Trial Attorney Injury Lawyer Houston tx , Baltimore Mesothelioma Attorneys , Mesothelioma Care ,Mesothelioma Trial Attorney ,Mesothelioma Lawyer Texas , Mesothelioma Lawyer Dallas , Mesothelioma Care , Mesothelioma Trial Attorney , Mesothelioma Lawyer Texas , California Mesothelioma Attorney Philadelphia Mesothelioma Lawyer , Illinois Mesothelioma Lawyer , Mesothelioma Attorney , Mesothelioma Claims , Average Mesothelioma Settlement
Integrated ehr , Mesothelioma Law Sui , Mesothelioma Lawyer California,Mesothelioma Attorney California ,Mesothelioma Law Suits ,Dallas Mesothelioma Attorneys ,Mesothelioma Drug ,Mesothelioma Attorney Directory