Far more readable r than trying to match curly brackets
<?php
$a = isset($a) ? $a : 'IS NOT SET';
if ($a == 5):
echo "a equals 5";
echo "...";
elseif ($a == 6):
echo "This will NOT crash, as the syntax is now legal ==> " .$a;
elseif ($a == 7):
echo "This will NOT crash, as the syntax is now legal ==> " .$a;
elseif ($a == 8):
echo "This will NOT crash, as the syntax is now legal ==> " .$a;
else:
echo "This will NOT crash, as the syntax is now legal ==> " .$a;
endif;
It will really help if you understood the rules; the language.
See PHP: if - Manual. It states that an if statement consists of an expression and a statement. It also says that the statement can actually be a group (the C and C++ languages call them blocks); something consisting of braces (“{}”) enclosing zero or more statements.
Then see PHP: else - Manual. Now this is an example of where the PHP manual is “friendly” but not precise. It shows the syntax of the else statement as having the braces, and it should not. It should show the else as consisting only of a statement in which the statement can optionally be a group (with braces). Also, the C and C++ manuals document the else as being an optional component of the if statement. The PHP manual documents “else” as a separate statement and implies but does not state explicitly that an else can only exist after an if.
The esleif statement just combines the else and if; I am not sure but I assume the only difference is that there is no space in elseif.
If you understand that syntax then you can understand the proper syntax for doing what you asked about and you will better understand if and else in the future.