Ternary operators and variable reassignment in PHP

后端 未结 4 1235
爱一瞬间的悲伤
爱一瞬间的悲伤 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:20

    In this cases, I use the form presented by BoltClock:

    if (strlen($foo) > 3) {
        $foo = substr($foo, 0, 3);
    }
    

    PHP does not implement something more simple to work in this cases, yet :/

提交回复
热议问题