PHP 三元運算 ??與?:

//$c = $a ?? $b;  等效  $c = isset($a) ? $a : $b;
//$c = $a ?: $b; 等效  $c = $a ? $a : $b;

$a = 'a';
$b = 'b';

$c = $a ?? $b; //a
$c = $a ?: $b; //a


$a = false; $b = 'b';
$c = $a ?? $b; //false $c = $a ?: $b; //b
相關文章
相關標籤/搜索