I'm going through the backlog of links I wanted to talk about when I come across this lovely PHPism:
elseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to
FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to
There may be several elseifs within the same if statement. The first elseif expression (if any) that evaluates to
TRUEwould be executed. In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word). The syntactic meaning is slightly different (if you're familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior.
The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to
FALSE, and the current elseif expression evaluated to
Note: Note that elseif and else if will only be considered exactly the same when using curly brackets as in the above example. When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.
So what this insane bit of verbiage is saying, is that “elseif” and “else if” are the same, except when they're not, which has to do with using either braces to separate code, or colons (which I'm not familiar with syntax wise in PHP). In effect, PHP supports both “elseif” and “else if” but with slightly different subtle semantics that could trip you up if you aren't careful.
Please, pick one, or the other, but not both! Sheesh!