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

Using the '??' operator in PHP7

青灯夜游
Release: 2023-02-17 14:14:01
forward
17387 people have browsed it

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;
Copy after login

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
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template