3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array('foo','bar','key'=> array('piff','puff','paff')); var_dump('TEST 1'); foreach($array as $key) {var_dump($key);} var_dump('TEST 2'); foreach($array[0] as $key) {var_dump($key);} var_dump('TEST 3'); foreach($array['key'] as $key) {var_dump($key);}
Output for 4.3.0 - 4.3.10, 4.4.0 - 7.1.0
string(6) "TEST 1" string(3) "foo" string(3) "bar" array(3) { [0]=> string(4) "piff" [1]=> string(4) "puff" [2]=> string(4) "paff" } string(6) "TEST 2" Warning: Invalid argument supplied for foreach() in /in/DdpBG on line 8 string(6) "TEST 3" string(4) "piff" string(4) "puff" string(4) "paff"
Output for 4.3.11
string(6) "TEST 1" string(3) "foo" string(3) "bar" array(3) { [0]=> string(4) "piff" [1]=> string(4) "puff" [2]=> string(4) "paff" } string(6) "TEST 2" string(6) "TEST 3" string(4) "piff" string(4) "puff" string(4) "paff"