In this tutorial we will study about if control structure.What is the use of if and how to implement are discussed in this tutorial.Examples in this tutorial will make it more clear.
In this tutorial we will study about if control structure.What is the use of if and how to implement are discussed in this tutorial.Examples in this tutorial will make it more clear.The If Construct:
The if construct is present in most of the famous computer languages, PHP uses the if construct to check the execution of code fragments. The if structure in PHP is similar to theExample:
<?php
$a=34;
$b=45;
if($a<$b)echo"\$a is smaller";
?>
Output:
$a is smaller
Example:
<?php
$a=34;
$b=34;
if($a<$b)echo"\$a is smaller<br/>";
if($a>$b)echo"\$a is bigger<br/>";
if($a==$b)echo"\$a is equal to \$b<br/>";
?>
Output:
$a is equal to $b
Example:
<?php
$a=34;
$b=3;
$c=45;
if($a>$b)
{
if($a>$c)
echo "\$a is greatest";
}
if($b>$a)
{
if($b>$c)
echo "\$b is greatest";
}
if($c>$a)
{
if($c>$b)
echo "\$c is greatest";
}
?>
Output:
$c is greatest