官方文件说:
如果第二个参数(关联)为NULL,则现在使用json_decode()函数选项JSON_OBJECT_AS_ARRAY。以前,JSON_OBJECT_AS_ARRAY始终被忽略。
此代码(AFAIK)完成了此更改和条件:
<?php
$an_object = new StdClass();
$an_object->some_atrribute = "value 1";
$an_object->other_atrribute = "value 2";
//an object
print_r($an_object);
$encoded = json_encode($an_object);
//here (null is passed in the second parameter)
$output = json_decode($encoded,null,512);
//using 7.2 should be array, however it is an object
print_r($output);
//array
$output = json_decode($encoded,true);
print_r($output);
Run Code Online (Sandbox Code Playgroud)
但是,仅最后一次打印以数组形式打印。
我理解不对吗?