3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = "unchecked"; $a = array(1, 2, 3, "is_ref" => &$x); foreach ($a as $k => $v) { if ($k !== "is_ref") { /* CODE FOR TESTING HERE */ // This will cause a copy: //$a[$k] = null; //$v += 1; //$a[$k] = $v; // This won't: //var_dump($a); } else if (isset($x)) { $x = "was not copied"; unset($x); $tmp = $a; $tmp["is_ref"] = "WAS COPIED!!!"; unset($tmp); echo "######### \$a is ".$a["is_ref"]."\n"; } }
Output for 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
######### $a is was not copied

preferences:
184.08 ms | 404 KiB | 219 Q