> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP Elseif Clause

The `elseif` clause is a conditional control structure chained after an `if` block as part of a broader `if` statement. It executes its associated statement block only if the preceding `if` condition, and any preceding `elseif` conditions, evaluate to `false`, and its own condition evaluates to `true`.

## Standard Syntax

In standard PHP syntax using curly braces, `elseif` is declared immediately following the closing brace of the preceding `if` or `elseif` block.

```php theme={"dark"}
if ($expression1) {
    // Executes if $expression1 is true
} elseif ($expression2) {
    // Executes if $expression1 is false AND $expression2 is true
} elseif ($expression3) {
    // Executes if $expression1 and $expression2 are false AND $expression3 is true
} else {
    // Executes if all preceding expressions are false
}
```

## Execution Mechanics

1. **Sequential Evaluation:** The PHP engine evaluates the expressions strictly in the order they appear.
2. **Boolean Context:** Every expression passed to an `elseif` is implicitly cast to a boolean value (`true` or `false`) prior to evaluation.
3. **Short-circuiting:** Once an `if` or `elseif` condition evaluates to `true`, its corresponding block is executed, and the engine immediately exits the entire control structure. Subsequent `elseif` conditions are never evaluated.

## `elseif` vs. `else if`

PHP supports both the single-word `elseif` and the two-word `else if`. When using standard curly brace syntax, their behavior is functionally identical.

However, at the parser level, `else if` (two words) is treated as an entirely new `if` statement nested implicitly within the `else` block of the preceding condition.

```php theme={"dark"}
// This:
if ($a) {
} else if ($b) {
}

// Is parsed identically to this:
if ($a) {
} else {
    if ($b) {
    }
}
```

## Alternative Syntax Constraints

PHP offers an alternative syntax for control structures using colons (`:`) and an `endif;` terminator. When utilizing this alternative syntax, **you must use the single-word `elseif`**.

Using the two-word `else if` in the alternative syntax will result in a fatal parse error.

**Valid Alternative Syntax:**

```php theme={"dark"}
if ($expression1):
    // statements
elseif ($expression2):
    // statements
else:
    // statements
endif;
```

**Invalid Alternative Syntax (Throws Parse Error):**

```php theme={"dark"}
if ($expression1):
    // statements
else if ($expression2): // Parse error: syntax error, unexpected token "if", expecting ":"
    // statements
endif;
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor PHP Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
