我刚刚观看了有关即将推出的 PHP 7.4 功能的视频,并看到了这个新功能??=
操作员。我已经知道了??
操作员。
这有什么不同?
来自docs https://wiki.php.net/rfc/null_coalesce_equal_operator:
合并等于或 ??= 运算符是赋值运算符。如果左侧参数为空,则将右侧参数的值赋给左侧参数。如果该值不为空,则不执行任何操作。
Example:
// The folloving lines are doing the same
$this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? 'value';
// Instead of repeating variables with long names, the equal coalesce operator is used
$this->request->data['comments']['user_id'] ??= 'value';
所以它基本上只是一个赋值的简写,如果它之前没有被赋值过的话。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)