Home > Article > Backend Development > What do two question marks mean in php
The two question marks in php are a new NULL merging operator ?? introduced in php7. Its use method is such as "$username = $_GET['user'] ?? 'nobody';".
#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
What do the two question marks in php mean?
In fact, the two question marks?? are new expressions introduced by php7:
In the PHP7 version, there is an additional NULL merge operator??, the example is as follows:
Example
<?php // 如果 $_GET['user'] 不存在返回 'nobody',否则返回 $_GET['user'] 的值 $username = $_GET['user'] ?? 'nobody'; // 类似的三元运算符 $username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; ?>
php7 used to often use ternary operation expressions:
Ternary operator:
Another conditional operator is " ?:" (or ternary) operator.
Syntax format
(expr1) ? (expr2) : (expr3)
The value when expr1 evaluates to TRUE is expr2, and when expr1 evaluates to FALSE, the value is expr3.
Since PHP 5.3, the middle part of the ternary operator can be omitted. The expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE and expr3 otherwise.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What do two question marks mean in php. For more information, please follow other related articles on the PHP Chinese website!