IF...ELSE

Conditional statements, tells the program to perform a certain instruction depending on the given condition.

IF

Executes the statement only if the condition is TRUE.

IF (condition) {
    statement
}

ELSE

Executes the alternate statement only if the condition is FALSE.

IF (condition) {
    statement
} ELSE {
    alternate statement 
}

ELSEIF

Executes the alternate statement only if the alternate condition of the ELSEIF is TRUE.

IF (condition) {
    statement
} ELSEIF (alternate condition) {
    alternate statement
}

Example


$x = 1
$y = 2
IF ($x > $y) {
    $result = "X is bigger than Y"
} ELSEIF ($x === $y) {
    $result = "X is equal to Y"
} ELSE {
    $result = "X is smaller than Y"
}
$result
⏯ run   🌐 open in tab
Copyright © SunSed LLC 2013-2022 All rights reserved.