PHP Conditions

Example 1: If/Else Condition

The program checks whether the person's age is at least 18.

The person is 18 or older.

Example 2: Switch/Case Condition

The switch statement checks the value of the $day variable and selects the matching case.

Today is Monday.

How Conditions Work

Conditions allow a PHP program to make decisions based on whether something is true or false. An if/else statement tests a condition and chooses between different blocks of code. A switch statement compares one value against several possible cases. Conditions are important because they allow programs to respond differently depending on the information they receive.

Back to Activity 3