If and else if in PHP, colon style

后端 未结 1 516
臣服心动
臣服心动 2021-02-07 10:45

One function of PHP that I like to use is the colon-style if statement (I don\'t know what it\'s actually called.)


    

        
相关标签:
1条回答
  • 2021-02-07 11:42

    I was able to get it to work.

    In this very specific case, else if is not synonymous with elseif.

    Substituting elseif for else if fixes the issue.

    <?php if(something):?>
        <html stuff>
    <?php elseif(something):?>
        <html stuff>
    <?php endif;?>
    

    From PHP.net:

    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.

    0 讨论(0)
提交回复
热议问题