Condition Statement -: we have seen php program is a set of statements which are normally executed sequentially in the order in which they appear.this happens when no option or no repetition for certain calculation are necessary. When we are writing a code in a program then there are some time we get some condition in this situation we write a condition statement .
Types of condition statement in php -: Php support for type condition statement these are the
- IF statement –: This statement was used when the condition is one and it s true only.
- If….else statement -: when the condition may be true or false this statement was used.
- If…..elseif…..false statement -: When the statement was checked multiple condition it may be true and another was false.
- Switch statement -: Its select one of many condition.
if statement withe example in php-: when the condition is true.For example
<?php $x = 20; if ($x >"10"){ echo "This is good for us "; } ?>
Result of this program
This is good for us
If…else statement with example -:This is use two condition one is true and another was false. For example
<?php $x = 20; if ($x >"10"){ echo "This is good for us "; } else { echo "This is not good for us"; } ?>
Result of this program
This is good for us
if…elseif ….else statement in php-: when the multiple condition are use in the program for example
<?php $x = 20; if ($x >"10"){ echo "This is good for us "; } elseif ($x > "25") { echo "This is best for us "; } else { echo "This is not good for us "; } ?>
Result of this program
This is good for us
Switch statement in php -:When the multiple condition are use in the program then we use this. For example
<?php
$x=10;
switch($x){
case 10:
echo("number are same 10");
break;
case 20:
echo("number are same 20");
break;
case 30:
echo("number are same 30");
break;
default:
echo("number are not same");
}
?>
Result of this program
number are same 10