elibraryportal Logo

If...Else Statements in PHP

If....else statements are used to perform different actions on different conditions.

There are following statements in PHP .

  1. if statement
  2. if...else statement
  3. if...elseif....else statement
  4. switch...case statement

1) if Statement in PHP.

If the condition is true, then the statement is executed. If the condition is not true , then the statement is not executed then instead the program skip past it.

Syntax

If Statement

Example :-

Output

Have a nice Day!
 

2) if...else Statement in PHP.

if-else are two condition . first condition is true this is executed, and second is false.

Syntax :-

Example :-

Output

Condition is false
 

3) if...elseif...else Statement in PHP

if....elseif...else statement executes different codes, more than two conditions.

Or

Multiple Statement, executes one Condition.

Syntax

Example :-

Output

Have a nice weekend!
 
Next Topic