PHP的json_decode函数有一个“深度”参数,您可以在其中指定深度进行递归的人。但是,下面的代码:PHP的json_decode的深度参数不起作用
test = array(
'name' => 'sean',
'dob' => '12-20',
'parents' => array(
'father' => 'tommy',
'mother' => 'darcy'
)
);
foreach(range(1, 3) as $depth) {
echo "-----------------\n depth: $depth\n";
print_r(json_decode(json_encode($test), true, $depth));
}
产生这样的输出:
-----------------
depth: 1
-----------------
depth: 2
-----------------
depth: 3
Array
(
[name] => sean
[dob] => 12-20
[parents] => Array
(
[father] => tommy
[mother] => darcy
)
)
什么我希望是深度为1,以示“名”和“出生日期”,和深度为2的展现父母也。我不明白为什么1或2的深度没有任何显示。
任何人都可以向我解释我不了解什么吗?
2013-10-15
Sean