Last active
March 25, 2017 21:53
-
-
Save Noitidart/911f10fca3f7e689cb1fc4b52b56a5e9 to your computer and use it in GitHub Desktop.
_php-array-merge-ref-preservation - Shows that references are presereved when merging arrays with +=
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 | |
$foo = 12; | |
$a1 = ['foo' => &$foo]; | |
$showa1 = function() use(&$a1) { | |
print_r($a1); | |
}; | |
$bar = 100; | |
$a2 = ['bar' => &$bar]; | |
// $merged = array_merge($a1, $a2); | |
$a1 += $a2; | |
// $a1['foo'] = 24; | |
// $a1['bar'] = 9; | |
// print assert($foo === 24); // works just fine | |
// print assert($bar === 9); // works just fine | |
$a1['foo'] = 24; | |
$bar = 9; | |
print assert($foo === 24); // works just fine | |
print assert($a1['bar'] === 9); // works just fine | |
$showa1(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment