$z = $x ?? $y;
//等价于下面
$z = isset($x) ? $x : $y;

$z = $x ?: $y;
//等价于下面
$z = $x ? $x : $y;


 

实例1:



<?php  
$x = 1; $y = 2;
$z = $x ?? $y;
echo 'z:'.$z;
$zz = $x ?: $y;
echo 'zz:'.$zz;
//输出是
z:1zz:1


实例2:



$x = 0; $y = 2;
$z = $x ?? $y;
echo 'z:'.$z;
$zz = $x ?: $y;
echo 'zz:'.$zz;
//输出是
z:0zz:2


实例3:



$y = 2;
$z = $x ?? $y;
echo 'z:'.$z;
$zz = $x ?: $y;
echo 'zz:'.$zz;
//输出是
z:2
Notice: Undefined variable: x in D:\PHPWAMP_IN2\phpwamp\server\Nginx-PHPWNMP\htdocs\test2.php on line 5
zz:2