3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('MAX_LOOPS',5); function withRefValue($elements, $transform) { echo "\n---( Array with $elements element(s): )---\n"; //Build array: for ($i=0; $i<$elements; $i++) { $a[] = "v.$i"; } $counter=0; echo "--> State of array before loop:\n"; var_dump($a); echo "--> Do loop:\n"; foreach ($a as $k=>&$v) { echo " iteration $counter: \$k=$k; \$v=$v\n"; eval($transform); $counter++; if ($counter>MAX_LOOPS) { echo " ** Stuck in a loop! **\n"; 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);
Output for git.master, git.master_jit, rfc.property-hooks
Popping elements off end of an unreferenced array, using &$value. ---( Array with 1 element(s): )--- --> State of array before loop: array(1) { [0]=> string(3) "v.0" } --> Do loop: iteration 0: $k=0; $v=v.0 --> State of array after loop: array(0) { } ---( Array with 2 element(s): )--- --> State of array before loop: array(2) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" } --> Do loop: iteration 0: $k=0; $v=v.0 --> State of array after loop: array(1) { [0]=> &string(3) "v.0" } ---( Array with 3 element(s): )--- --> State of array before loop: array(3) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" } --> Do loop: iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 --> State of array after loop: array(1) { [0]=> string(3) "v.0" } ---( Array with 4 element(s): )--- --> State of array before loop: array(4) { [0]=> string(3) "v.0" [1]=> string(3) "v.1" [2]=> string(3) "v.2" [3]=> string(3) "v.3" } --> Do loop: iteration 0: $k=0; $v=v.0 iteration 1: $k=1; $v=v.1 --> State of array after loop: array(2) { [0]=> string(3) "v.0" [1]=> &string(3) "v.1" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.97 ms | 403 KiB | 8 Q