Created
September 21, 2019 22:51
-
-
Save Chemaclass/56f3f4e405bb780a9bde41060e031f89 to your computer and use it in GitHub Desktop.
Docu - Null coalescing operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // 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'; | |
| // Coalescing can be chained: this will return the first | |
| // defined value out of $_GET['user'], $_POST['user'], and | |
| // 'nobody'. | |
| $username = $_GET['user'] ?? $_POST['user'] ?? 'nobody'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment