syntax error, unexpected ‘elseif’¶
Description¶
The elseif must follow a if structure. It cannot be used alone, not be used after a else clause.
Example¶
<?php
// elseif cannot be standalone
elseif ($a === 1) {
echo 2;
}
// else has closed the if structure, not more elseif allowed
if ($condition) {}
else {}
elseif ($a === 1) {
echo 2;
}
// the endif; has already closed the if structure.
if ($condition):
endif;
elseif ($a === 1) :
echo 2;
endif;
?>
Solutions¶
Ensure that there is a previous
ifstructure, with onethenblock, and optionally, otherelseifblock.Ensure that there is no previous
elseclause.Ensure that there is no previous
endifkeyword.