Created
January 2, 2019 10:58
-
-
Save DeeSouza/9180a031b3fb604f1031b50b33fb9a64 to your computer and use it in GitHub Desktop.
Operator Null Coalesce - PHP 7.0+
This file contains 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 | |
/* Operador Null Coalesce - '??' */ | |
// IF Ternário - Muito comum ao fazer uma condição inline | |
$username = (isset($_GET['username'])) ? $_GET['username'] : 'Diego'; | |
// Usando o operador Null Coalesce você pode reduzir a condição. | |
$username = $_GET['username'] ?? 'Diego'; | |
// E ainda pode fazer uma verificação dupla | |
$username = $_GET['username'] ?? $_POST['username'] ?? 'Diego'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment