If statement is a control statement. The body of the if statement is executed when condition is true or nonzero. In PHP we can pass either Boolean value or any other value.
if (condition) {
code to be executed if condition is true;
}
<?php
$a=10;
$b=10;
if($a==$b)
{
echo"successful";
}
?>
It is also a control statement. It is very useful in programming. If condition is not true the else part executed. Else has no condition.
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
<?php
$a=10;
$b=10;
if($a==$b)
{
echo"successful";
}
else
{
echo"failure";
}
?>
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}
<?php
$a=10;
$b=10;
$c=10;
if($a > $b and $a > $c)
{
echo"a is largest.";
}
elseif($b > $a and $b > $c)
{
echo"b is largest";
}
elseif($c > $a and $c > $b)
{
echo" c is largest";
}
else
{
echo"a=b=c";
}
?>