@ 2017-07-05T18:29:12Z <?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
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.27 , 8.2.0 - 8.2.17 , 8.3.0 - 8.3.4 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 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 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"
}
preferences:dark mode live preview
139.29 ms | 402 KiB | 184 Q