Overview of PHP shorthand

后端 未结 9 1365
小鲜肉
小鲜肉 2020-12-12 15:32

I\'ve been programming in PHP for years now, but I\'ve never learned how to use any shorthand. I come across it from time to time in code and have a hard time reading it, s

9条回答
  •  心在旅途
    2020-12-12 15:45

    PHP 5.3 introduced:

    $foo = $bar ?: $baz;
    

    which assigns the value of $bar to $foo if $bar evaluates to true (else $baz).

    You can also nest the ternary operator (with proper use of parenthesis).

    Other than that, there is not much else about it. You might want to read the documentation.

提交回复
热议问题