Skip to content

Instantly share code, notes, and snippets.

@woprrr
Created March 5, 2020 09:52
Show Gist options
  • Save woprrr/08334073a050f35ef39ac6864013721b to your computer and use it in GitHub Desktop.
Save woprrr/08334073a050f35ef39ac6864013721b to your computer and use it in GitHub Desktop.
Null Coalescing Assignment Operator examples. Try it now : https://3v4l.org/pV6PF
<?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