Conditions in PHP

Conditions are used to implement logic into your code.

Conditions use operators and can be used to compare statements, execute code if specific conditions are met, etc.

One important way to express conditions is using an if statement.

An example if statment might look like:

if (x > y) { do something } else { do something else }

In this if statement, the "do something" code will only be executed if x is greater than y.

If x is NOT greater than y, the "do something else" code will be executed. We achieve this by using an else statement, which will only run if the condition in the if statement is false.


if/else Example:

Today is neither Monday or Wednesady. It is actually Friday.

Switch & Case Example:

Today is a Friday! I love Fridays! They are the start of the weekend!