3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a1=['0'=>'my key should be a (numeric) string']; $a2=[0=>'my key should be an int']; $a3= new stdClass; $a3->{"0"} = 'my key should be a (numeric) string'; $a3=(array)$a3; foreach($a1 as $key=>$val){echo $val.': ';var_dump($key);} foreach($a2 as $key=>$val){echo $val.': ';var_dump($key);} foreach($a3 as $key=>$val){echo $val.': ';var_dump($key);} var_dump($a1,$a2,$a3);
based on WrFNR
Output for 7.2.0
my key should be a (numeric) string: int(0) my key should be an int: int(0) my key should be a (numeric) string: int(0) array(1) { [0]=> string(35) "my key should be a (numeric) string" } array(1) { [0]=> string(23) "my key should be an int" } array(1) { [0]=> string(35) "my key should be a (numeric) string" }
Output for 5.4.0 - 5.6.30, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.1.10
my key should be a (numeric) string: int(0) my key should be an int: int(0) my key should be a (numeric) string: string(1) "0" array(1) { [0]=> string(35) "my key should be a (numeric) string" } array(1) { [0]=> string(23) "my key should be an int" } array(1) { ["0"]=> string(35) "my key should be a (numeric) string" }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/vQCck on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/vQCck on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/vQCck on line 3
Process exited with code 255.