Ternary operators and variable reassignment in PHP

后端 未结 4 1225
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-20 08:22

I\'ve perused the questions on ternary operators vs. if/else structures, and while I understand that under normal circumstances there is no performance los

4条回答
  •  我在风中等你
    2020-12-20 09:26

    There is always short-circuiting, although as @BoltClock said, an if statement is probably more readable in my opinion, and opens the door to else if and else conditions as well.

    strlen($foo) > 3 && $foo = substr($foo, 0, 3); 
    

    The latter statement will only be executed if the former evaluates to TRUE.

提交回复
热议问题