IF..ELSE is used in PHP to provide conditional judgements. The basic syntax is as follows:
IF (conditional statement) {
[code if condition is true]
}
ELSE {
[code if condition is false]
}
Let's see an example. Assuming we have the following piece of code:
$sample = 10; IF ($sample > 5) { print "Number is greater than 5"; } ELSE { print "Number is less than 5"; } |
Number is greater than 5 |
Previous Page->PHP-Operators || Next Page->PHP-else-if