Use the if statement to test some condition. The condition is contained in parentheses

If the condition is true, run some PHP code. If the condition is false, do not run the code.

The condition is followed by a pair of curly braces, also known as a block, like this: {}. The block contains code which will run if the condition is true.

The block is not followed by a semicolon. However, statement inside the block is followed by a semicolon.

Syntax:

if (true) {
// run this code block if condition is true
}

Example:

$var = 5;
if ($var == 5) {
print "Yes, the value is five.";
}

The equality operator (double equals sign, ==) tests if two things are equal to each other.

Don’t confuse the equality operator with the assignment operator (single equals sign, =).

Use the else clause to run a block of code when a test is not true.

Syntax:

if (true) {
// run this code block if condition is true
} else {
// run this other code block if condition is false
}

You can combine if and else in a variety of ways, to perform tests of any complexity.

Use a series of if … else if … else if … else statements to test a series of clauses. If the first condition is true, the associated code block runs, and the series is done. But if the first condition is false, the series continues with the second condition: if true, the second code block runs and the series is done, if false the series continues with the third condition, and so on. Use a final else clause for code you want to run if none of the conditions in the series are true.

if (true) {
  // run this code block if condition is true
} elseif (true) {
  // run this code block if second condition is true
} elseif (true) {
  // Third option
} else{
// run this code block if none of the above are true
}

See also

If … Else Statements @ w3schools