Created
November 30, 2015 14:17
-
-
Save ThijsFeryn/9a012a4425dc368d0981 to your computer and use it in GitHub Desktop.
PHP 7 null coalesce 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 | |
/** | |
* Null coalesce operator | |
*/ | |
$array = ['foo'=>'bar']; | |
//PHP5 style | |
$message = isset($array['foo']) ? $array['foo'] : 'not set'; | |
echo $message.PHP_EOL; | |
//PHP7 style | |
$message = $array['foo'] ?? 'not set'; | |
echo $message.PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment