if statement in PHP

“if” statement is one of the most important and most used construct in PHP programming.

Its syntax will look like

if  (expression)
// Operation statements

if statement’s return result will be a Boolean value like TRUE or FALSE.
If the expression with “if statement” returns TRUE, the Operation Statements will execute , otherwise it will ignore the statements.

See the sample PHP program with if statement

$x = 10;
if ( $x < 15 )
 echo " First Statement Executed ";
if ( $x > 15 )
 echo " Second Statement Executed ";

Output of this program will be :
First Statement Executed

In this case ( $x < 15 ) will return TRUE because 10 is less than 15, so the code inside the if block will execute. ( $x > 15 ) will return FALSE and the code inside that if loop wont execute and wont display “Second Statement Executed” in result.

We can use the if statements in a nested structure with else , elseif statements.
See the next posts for learn about those.