PHP If…Else

The if...else statement executes one block of code if a condition is true and another block if the condition is false.

Tutorials dojo strip

Syntax

PHP

Example

Here’s an example based on motorcycles. If you own fewer than 5 motorcycles, it suggests buying a Yamaha; otherwise, it suggests riding a Honda:

PHP

PHP – The if…elseif…else Statement

The if...elseif...else statement allows you to evaluate multiple conditions and execute different blocks of code accordingly.

Syntax

PHP

Example

Consider this example based on cars. If someone has fewer than 2 cars, it suggests a Tesla; if they own between 2 and 5, it suggests a Toyota; otherwise, it recommends driving a BMW:

PHP
Tutorials dojo strip