3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $son = '{ "1":{ "id":"1", "name":"jack" }, "2":{ "id":"2", "name":"john" } }'; $json = (array) json_decode($son); //var_dump($json); var_dump($json['1']); // incorrect result var_dump($json[1]); // incorrect result $json = json_decode($son,true); var_dump($json['1']); // correct result
based on D5bjB
Output for 7.2.0 - 7.3.0rc3
object(stdClass)#1 (2) { ["id"]=> string(1) "1" ["name"]=> string(4) "jack" } object(stdClass)#1 (2) { ["id"]=> string(1) "1" ["name"]=> string(4) "jack" } array(2) { ["id"]=> string(1) "1" ["name"]=> string(4) "jack" }
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.20
Notice: Undefined offset: 1 in /in/CS6BJ on line 10 NULL Notice: Undefined offset: 1 in /in/CS6BJ on line 11 NULL array(2) { ["id"]=> string(1) "1" ["name"]=> string(4) "jack" }
Output for hhvm-3.15.4
Notice: Undefined index: 1 in /in/CS6BJ on line 10 NULL Notice: Undefined index: 1 in /in/CS6BJ on line 11 NULL array(2) { ["id"]=> string(1) "1" ["name"]=> string(4) "jack" }