3v4l.org

run code in 300+ PHP versions simultaneously
<?php $params = [1,2,3]; function transform(array &$params) { $references = []; foreach ($params as &$value) { $references[] = &$value; } $value = "foo"; return $references; } var_dump($params); $p = transform($params); var_dump($params); var_dump($p); debug_zval_dump($params); debug_zval_dump($p);
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" } array(3) { [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" } array(3) refcount(2){ [0]=> reference refcount(2) { int(1) } [1]=> reference refcount(2) { int(2) } [2]=> reference refcount(2) { string(3) "foo" interned } } array(3) refcount(2){ [0]=> reference refcount(2) { int(1) } [1]=> reference refcount(2) { int(2) } [2]=> reference refcount(2) { string(3) "foo" interned } }
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" } array(3) { [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" } array(3) refcount(2){ [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" refcount(1) } array(3) refcount(2){ [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" refcount(1) }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } array(3) { [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" } array(3) { [0]=> &int(1) [1]=> &int(2) [2]=> &string(3) "foo" } array(3) refcount(2){ [0]=> &long(1) refcount(2) [1]=> &long(2) refcount(2) [2]=> &string(3) "foo" refcount(2) } array(3) refcount(2){ [0]=> &long(1) refcount(2) [1]=> &long(2) refcount(2) [2]=> &string(3) "foo" refcount(2) }

preferences:
237.17 ms | 402 KiB | 326 Q