gpt4 book ai didi

php - 是否有一种叫做空合并运算符的东西,比如 Null 合并运算符

转载 作者:行者123 更新时间:2023-12-04 13:03:05 24 4
gpt4 key购买 nike

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';

最佳答案

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

关于php - 是否有一种叫做空合并运算符的东西,比如 Null 合并运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49608972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com