3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Set everything up $testArray = array( 'a' => array(), 'b' => array() ); $saved = array(); $ref =& $testArray['b']; // Set a value via the reference $ref = array(1); // Save the current array state $saved[] = $testArray; // This shouldn't be a reference, right? // Set another value via the reference $ref = array(2); // Save the current array state $saved[] = $testArray; // This shouldn't be a reference, right? var_dump($saved);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(2) { [0]=> array(2) { ["a"]=> array(0) { } ["b"]=> &array(1) { [0]=> int(2) } } [1]=> array(2) { ["a"]=> array(0) { } ["b"]=> &array(1) { [0]=> int(2) } } }