If/Else Statement in Php


An If statement can be followed by an optional else statement, which executes when the Boolean expression is false.

The syntax of if....else statement in Php is

if(condition)
{
    /* statements will execute if the condition is true */
}
else
{
    /* statements will execute if condition will false */
}

If all the conditions get true then 'if' block will be executed, otherwise 'else' block will be executed.

Example :-
<!DOCTYPE html>
<html>
<head><title>expertcodingmaster.com</title>
</head>
<body>
<?php
$a = 20;   
$b = 10;   
if($b > $a)
{
echo "B is greater";
}
else
{
echo "A is greater";
}

?>
</body>
</html>

Output of the above code
A is greater



No comments: