是否存在称为空合并运算符的内容,如Null合并运算符

时间:2018-04-02 09:50:01

标签: php function

PHP 7添加了null coalesce operator

// Fetches the value of $_GET['number'] and returns 'nonumber -NULL'
// if it does not exist.
$username = $_GET['number'] ?? 'No Number';
// This is equivalent to:
$username = isset($_GET['number']) ? $_GET['number'] : 'No Number';

还有空的东西吗?

寻找类似的东西,

/ Fetches the value of $_GET['number'] and returns '0' Empty
// if it does not empty.
$username = $_GET['number'] ?? 'no number or number is 0 or empty';

1 个答案:

答案 0 :(得分:0)

是的,感谢类型强制the short ternary operator ?:

相关问题