In php7, two interesting operators have been added ?? and ?:
What is the difference between ?? (NULL coalescing operator) and ?:?
(1)?? is as long as the previous variable is defined (that is, isset() is true) or the previous expression is true, then the previous value will be returned.
(2)?: The expression or variable value in front of the operator needs to be true, then the previous value is taken, and if it is false, the latter value is taken. But the premise is that the previous variables need to be defined and already exist.
echo $i ?? 3. PHP_EOL; $arr = ; echo $arr['xxx'] ??'yyy';
The above is equivalent to:
echo isset($arr['xxx'])? $arr['xxx']:'yyy';
For ?: is slightly different:
If you open php and report an error, a warning will be generated for undefined variables.
If you confirm that the variable has been set, it is recommended to use?:
Recommended for other situations?
In the case of uncertain whether the variable exists, there will be cases where the variable expression value is empty and the initial value cannot be accurately set.