Curly braces or colon-endif statements in PHP - which one provides better performance and code compatibility?

前端 未结 5 1797
耶瑟儿~
耶瑟儿~ 2021-01-07 22:03

I was looking through many snippets of code, and I have found that people can use the following two methods in an if statement:

Method 1:



        
5条回答
  •  臣服心动
    2021-01-07 22:52

    Most of the time the alternative (endif) syntax is used in view scripts. It's often hard to see/notice the end of an if statement since a curly brace only takes up one character, when you're at the bottom of a file, it's hard to tell if it's the end of an if or a foreach. For example:

    
    
        
    a huge block of html

提交回复
热议问题