欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP 三元运算 ??与?:

程序员文章站 2022-04-08 18:49:27
//$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 = fa... ......
//$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