Transfer of Control In PHP

If Statements in PHP

The IF structure is one of the most important features of any programming languages which provide the conditionally transfer of control. The PHP IF structure is similar to the C language IF structure.

Syntax:

if (expr)

{


statement 1;

statement 1;

}
Where expression is any logical expression. If expression evaluates to TRUE then the statement in the body of IF structure will be executed other wise control transfer to next statement. 

Note: if you have a single statement in the body of IF then there is no need of opening parentheses { and closing parenthesis }.

The following example compare the two value and give the large value.


<?php
if ($a > $b)
echo "a is larger than b";
?>

If you have more then one statements in the body of the if statement then you must place all statement in the opening parenthesis and closing parenthesis.


<?php
if ($a > $b)

{
echo "a is larger than b";
echo "done";
}
?>