PHP If Else

PHP if else statement is used to test condition. There are various ways to use if statement in PHP.

PHP If Statement

PHP if statement allows conditional execution of code. It is executed if condition is true.

If statement is used to executes the block of code exist inside the if statement only if the specified condition is true.

Syntax

Flowchart

php if statement flowchart

Example

Output:

12 is less than 100

PHP If-else Statement

PHP if-else statement is executed whether condition is true or false.

If-else statement is slightly different from if statement. It executes one block of code if the specified condition is true and another block of code if the condition is false.

Syntax

Flowchart

php if-else statement flowchart

Example

Output:

12 is even number

PHP If-else-if Statement

The PHP if-else-if is a special statement used to combine multiple if?.else statements. So, we can check multiple conditions using this statement.

Syntax

Flowchart

php if-else statement flowchart

Example

Output:

B Grade

PHP nested if Statement

The nested if statement contains the if block inside another if block. The inner if statement executes only when specified condition in outer if statement is true.

Syntax

Flowchart

php if-else statement flowchart

Example

Output:

Eligible to give vote

PHP Switch Example

Output:

34 is smaller than 56 and 45

Next TopicPHP Switch




Contact US

Email:[email protected]

PHP If else
10/30