PHP Decision Making

In PHP, decision making statements or conditional statements are the statements which are used to deciding the order of execution of statements based on certain conditions or perform different types of actions based on different actions.

Basically, decision making statements are used while making a decision. For example - If statement executes a code only upon a specific condition is true.

Different types of decision making statements in PHP such as IF statement, IF Else statement,IF Elseif statement, switch case statement etc.

PHP If Statement

If statement executes a code only upon a specific condition is true.

Syntax

PHP If Statement Example

This will produce following result

PHP If....Else Statement

We can enhance any decision making process by adding an else statement to the if construction. This allows to run one block of code if an expression is true and a different block of code if the expression is false.

Syntax

PHP If....Else Statement Example

This will produce following result

Else...If Statement

We can even combine the else statement with another if statement to make as many alternative choices as we like:

Syntax

PHP Else...If Statement Example

This will produce following result