还有其他更简洁的方法来设置默认值吗? [英] Any more concise way to set default values?
本文介绍了还有其他更简洁的方法来设置默认值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
自PHP 5.3起,可以省略中间部分 三元运算符.表达式expr1?:如果expr1,则expr3返回expr1 计算结果为TRUE,否则为expr3.
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.
是否有比下面的代码更好或更简洁的方法来设置变量的默认值?
Is there any better or more concise way than following code to set default value of variables?
$v = isset($v) ? $v : "default value";
推荐答案
以下是较短的语法:
isset($v) || $v="default value";
这篇关于还有其他更简洁的方法来设置默认值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文