PHP "??" 合并空值运算符

2020-07-24 14:42:08 by Sikoay with 0 comments 1 Hits
Blog 1

今天在阅读一个组件源码时发现了 ?? 运算符,查找官网后发现时PHP7新加入的,记录一下


In addition to what Lawrence said about assigning a default value, one can now use the Null Coalescing Operator (PHP 7). Hence when we want to assign a default value we can write:

$a = ($fruit ?? 'apple');
//assigns the $fruit variable content to $a if the $fruit variable exists or has a value that is not NULL, or assigns the value 'apple' to $a if the $fruit variable doesn't exists or it contains the NULL value






回复 (0)

Leave a Comment