3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('MAX_LOOPS',5); function withRefValue($elements, $transform) { for ($i=0; $i<$elements; $i++) { $a[] = "v.$i"; } $counter=0; foreach ($a as $k=>$v) { eval($transform); $counter++; if ($counter>MAX_LOOPS) { break; } } echo "--> State of array after loop:\n"; var_dump($a); } echo "\nPopping elements off end of an unreferenced array, using &\$value."; $transform = 'array_pop($a);'; withRefValue(1, $transform); withRefValue(2, $transform); withRefValue(3, $transform); withRefValue(4, $transform); withRefValue(5, $transform); withRefValue(6, $transform); withRefValue(7, $transform); withRefValue(8, $transform); withRefValue(9, $transform); withRefValue(10, $transform); withRefValue(11, $transform); withRefValue(12, $transform);
based on qRjoV
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Popping elements off end of an unreferenced array, using &$value.--> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(0) { } --> State of array after loop: array(1) { [0]=> string(3) "v.0" } --> State of array after loop: array(2) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" } --> State of array after loop: array(3) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" } --> State of array after loop: array(4) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" } --> State of array after loop: array(5) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" } --> State of array after loop: array(6) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" [4]=> string(3) "v.4" [5]=> string(3) "v.5" }