Short version of $x ? $x : $y expression

My intention is to find a short version of:

$x ? $x : $y

where $x gets evaluated only once.


From the PHP manual entry on Comparison Operators :

Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise.

So, you'll need to be using PHP 5.3 or greater to get this "shortcut" feature. Although, why you'd want a shortcut for an operator that already is a shortcut is another question...


Yes, it is valid .

You know, you could have just tried it. :)

http://3v4l.org/68Zrf

链接地址: http://www.djcxy.com/p/57730.html

上一篇: 最短的if / else使用三元运算符

下一篇: 短版$ x? $ x:$ y表达式