If and more, if in PHP, colon style

One of the PHP functions that I like to use is the if-type operator of the colon (I don't know what it actually called.)

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

But I recently tried to do this with a few cases:

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

And I get an error in the third line ( else if ):

Unexpected T_IF

Is it possible to do if-else if so?

+6
source share
1 answer

I managed to get it to work.

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

Substituting elseif for else if fixes the problem.

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

From PHP.net :

Note. Note that elseif and else if will be considered exactly the same when using curly braces, as in the example above. When using a colon to determine your if / elseif conditions, you should not separate the else by two words, or PHP will fail with a parsing error.

+7
source

Source: https://habr.com/ru/post/985026/


All Articles