- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
- int(69) array(1) { ["a"]=> &int(69) }
<?php
// plain variable
$a = 42;
// array containing a reference
$b = [
'a' => &$a
];
// capture the array by-value
$f = function() use($b) {
// update the reference from inside the closure
$b['a'] = 69;
};
// call it
$f();
// observe that both the array and the plain variable now have the new value
var_dump($a, $b);