$array = ['name'=>'Jonh', 'lastname' => 'Doe', 'nickname' => 'JD'] ;
$person = $array['name'] ?? null ; //try to change null to true or false<br>
echo $person;
$person = $array['age'] ?? null; //no Undefined index: age<br>
echo $person;
Run Code Online (Sandbox Code Playgroud)
我找不到任何关于它的文档.
这是新的PHP7"null coalescing operator":
// Fetches the value of $_GET['user'] and returns 'nobody'
// if it does not exist.
$username = $_GET['user'] ?? 'nobody';
// This is equivalent to:
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
Run Code Online (Sandbox Code Playgroud)
而
三元运算符的 缩写形式?:多年来几乎相同(至少PHP 5.3)
| 归档时间: |
|
| 查看次数: |
69 次 |
| 最近记录: |