endforeach in loops?

前端 未结 7 1516
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 05:59

I use brackets when using foreach loops. What is endforeach for?

7条回答
  •  盖世英雄少女心
    2020-12-01 06:30

    It's mainly so you can make start and end statements clearer when creating HTML in loops:

    record has been deleted

    versus

    record has been deleted

    Hopefully my example is sufficient to demonstrate that once you have several layers of nested loops, and the indenting is thrown off by all the PHP open/close tags and the contained HTML (and maybe you have to indent the HTML a certain way to get your page the way you want), the alternate syntax (endforeach) form can make things easier for your brain to parse. With the normal style, the closing } can be left on their own and make it hard to tell what they're actually closing.

提交回复
热议问题