1. 程式人生 > >php中??和?:區別

php中??和?:區別

??和?:區別:

$headerVal = 0;

$this->params = $headerVal ?? 2; 相當於 isset($headerVal) ? $headerVal : 2; //結果是0

$this->params = $headerVal ?: 2; 相當於 !empty($headerVal) ? $headerVal : 2; //結果是2