How to use PHP if, else if, and endif – Syntax and Usage

The ‘If’ comes wherever options come. Where there is more than one option for anything for any matter we have to decide. In programing we use one of the method to handle this is by using If and if else statements, also known as decision making statements – to take decisions based on different situations.

Quick Reach

Three types of decision making statements in PHP

if…else statement

Use this statement when there are only two options or outcomes

Syntax



Example:



To execute more than one lines in true or false situation use curly braces as below



Using Else:



elseif statement

Use this option where you have more than 2 situations to execute code.

Syntax



Example:



Switch Statement

Use this option when you have many options and have to execute one of those. Go to this page

Was this article helpful?

Related Articles

Leave A Comment?