Home  >  Article  >  Backend Development  >  Using the '??' operator in PHP7

Using the '??' operator in PHP7

青灯夜游
青灯夜游forward
2020-04-12 09:49:2417372browse

How to use the "??" operator in PHP7? The following article will introduce to you the usage of "??" in PHP7. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Using the '??' operator in PHP7

?? operator in PHP7, let’s take a look at its specific function

?? is equivalent to

isset($a)? $a :$b;

Determine whether a variable a exists. If it exists, assign variable a. If it does not exist, assign variable b

Note that it is to determine whether a variable exists, not to determine whether a variable is empty

Look at the code directly

$a = $a ?? 1;
var_dump($a);//1

$a = 5;
$a = $a ?? 1;
var_dump($a);//5

$a = 0;
$a = $a ?? 1;
var_dump($a);//0

This article is reproduced from: https://blog.csdn.net/kelinfeng16/article/details/103111710

More programming related content , please pay attention to the Introduction to Programming column on the php Chinese website!

The above is the detailed content of Using the '??' operator in PHP7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete