Home  >  Article  >  Backend Development  >  In PHP, what does the double question mark (??) operator mean?

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

王林
王林forward
2023-08-19 13:57:133181browse

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;
?>

Output

9

Example

Chinese translation is:

Example

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

Output

34

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!

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