In PHP, what does the double question mark (??) operator mean?

王林
Release: 2023-08-19 14:00:02
forward
3246 people have browsed it

In PHP, what does the double question mark (??) operator mean?

#PHP 7 has added a new operator double question mark (??) operator. In PHP 7, the double question mark (??) operator is called the Null Coalescing operator.

If the first operand exists and is not NULL, return the first operand; otherwise, return the second operand. It is evaluated from left to right. The Null Coalescing operator can also be used in chained format.

Let us demonstrate the double question mark (??) operator with the following example.

Example

<?php
   //$a is not set
   echo $a ?? 9 ??45;
?>
Copy after login

Output

9
Copy after login

Example

Chinese translation is:

Example

<?php
   //$a is not set
   $b = 34;
   echo $a ?? $b ?? 7;
?>
Copy after login

Output

34
Copy after login

The above is the detailed content of In PHP, what does the double question mark (??) operator mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
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