3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // nice case of value after looping $a = array("one"=>1,"two"=>2,"three"=>3); echo "-----\nPointer\n-----\n"; foreach($a as &$b) { var_dump( key($a) ); var_dump( current($a) ); } echo "-----\nAfter iteration\n-----\n"; var_dump( key($a) ); var_dump( current($a) ); echo "-----\nNo pointer\n-----\n"; foreach($a as $b) { var_dump( key($a) ); var_dump( current($a) ); } echo "-----\nAfter iteration\n-----\n"; var_dump( key($a) ); var_dump( current($a) );
based on m3VWs
Output for 7.0.0 - 7.2.0
----- Pointer ----- string(3) "one" int(1) string(3) "one" int(1) string(3) "one" int(1) ----- After iteration ----- string(3) "one" int(1) ----- No pointer ----- string(3) "one" int(1) string(3) "one" int(1) string(3) "one" int(1) ----- After iteration ----- string(3) "one" int(1)
Output for 5.3.20 - 5.6.21
----- Pointer ----- string(3) "two" int(2) string(5) "three" int(3) NULL bool(false) ----- After iteration ----- NULL bool(false) ----- No pointer ----- string(3) "two" int(2) string(3) "two" int(2) string(3) "two" int(2) ----- After iteration ----- string(3) "two" int(2)