Created
March 5, 2020 09:52
-
-
Save woprrr/08334073a050f35ef39ac6864013721b to your computer and use it in GitHub Desktop.
Null Coalescing Assignment Operator examples. Try it now : https://3v4l.org/pV6PF
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 Coalescing Assignment Operator | |
# OLD WAY (PHP < 7.4 ) | |
$data['comments']['user_id'] = $data['comments']['user_id'] ?? 'PlaceHoldered value...'; | |
var_dump($data['comments']['user_id']); | |
$data = null; | |
# PHP 7.4 + syntax to use new assigment operator without unecessary tests. | |
$data['comments']['user_id'] ??= 'PlaceHoldered value...'; | |
var_dump($data['comments']['user_id']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment