if is a most important feature of PHP as in many languages like C.
if statements can be nested infinitely within other if statements.
Sometimes you want more than one statement to be executed conditionally.
This can be done using control statement if.
In if you have to group number of statements that you want to execute has to put within curly brace.


Syntax of if

Following is a general syntax of if control structure:

If expression evaluates to TRUE, PHP will execute statement, and if it evaluates to FALSE it will ignored.

Flowchart of if


Example of if-

This is a simple example of if structure.
In this, expression $a > $b is true therefore the statements inside if get executed.

Help others by sharing the content!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.