Guest User

Untitled

a guest
May 25th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. |--------------------------------------------------------------------------
  5. | NULL 合并运算符
  6. |--------------------------------------------------------------------------
  7. |
  8. | 由于日常使用中存在大量同时使用三元表达式和 isset() 的情况,NULL 合并运算符使得变量存在且值不为 NULL, 它就会返回自身的值,否则返回它的第二个操作数。
  9. |
  10. */
  11.  
  12.  
  13. // PHP 7 之前
  14. $name = isset($_GET['name']) ? $_GET['name'] : 'Anonymous';
  15.  
  16. echo $name;
  17.  
  18. // PHP 7 之后
  19. $name = $_GET['name'] ?? 'Anonymous';
  20.  
  21. echo $name;
Add Comment
Please, Sign In to add comment