When do I use if/endif versus If{}?

后端 未结 6 806
暗喜
暗喜 2021-02-08 08:30

Well the question is self explanatory.

In PHP when do I use the if/endif notation instead of the standard if(something){} notation?

Exa

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-08 09:09

    Short answer:

    Always use if($something) { } and pretty much never use if/endif. It's standard since PHP 4.0.0 and while the old syntax is not going away this is the one everybody expects.

    If you are really looking for a case where you can use if/endif then it's when using php as a template language.

    Some people like something like this:

    
    Hi There
    
    cya!
    
    

    better than

    
    Hi There
    
    cya!
    
    

    and imho it is because every line "speaks" and that can be helpful when there is a lot of html inbetween the php tags.

提交回复
热议问题