PHP if else statement

The IF Else statement provides a default block of code that executes if the condition returned is FALSE. else cannot be used without an if statement,as it doesn't take a conditional itself. So, else and if have to always be together in your code.

The IF Else statement Remember to close out the code block from the if conditional when you've used braces to start your block of code. Similar to the if block, the else block should also use curly braces to begin and end the code.

PHP if else syntax

<?php
if (condition)
{
------------
------------
------------
}
else
{
------------
------------
------------
}
?>

PHP if else Example


<?php if ($a > $b)
{
echo "a is bigger than b";
}
else
{
echo "b is bigger than a";
}
?>

In The Above Example there are two variables $a , $b . if the condition "$a > $b" is true then then message "a is bigger than b" is displayed other wise else statement messge "b is bigger than a" is displayed.





Content