Back to course

Conditional Logic: if, else, elseif

PHP: The Complete 0 to Hero Bootcamp

11. Conditional Logic: if, else, elseif

Conditional statements allow your script to make decisions based on whether a condition evaluates to true or false.

The if Statement

The most basic structure. The code block executes only if the condition is true.

php

= 70) { echo "Congratulations! You passed."; } ?>

The if...else Statement

Allows you to execute one block of code if the condition is true, and a different block if it is false.

php

= 18) { echo "You are eligible to vote."; } else { echo "You are too young to vote."; } ?>

The if...elseif...else Statement

Used for checking multiple conditions sequentially.

php

Logical Operators

To combine multiple conditions:

OperatorNameExample
&& or andAND($a > 10) && ($b < 5) (Both must be true)
`oror`
!NOT!$is_logged_in (Reverses the boolean value)

php