PHP의 json_decode 함수에는 "깊이"매개 변수가 있습니다.이 매개 변수를 사용하여 누가 다시 발생하는지 깊이 지정할 수 있습니다. 그러나 다음 코드 : 내가 기대하는 것은 "이름"과 "DOB"과를 보여 2의 깊이를 보여주는 하나의 깊이가PHP의 json_decode 깊이 매개 변수가 작동하지 않음
-----------------
depth: 1
-----------------
depth: 2
-----------------
depth: 3
Array
(
[name] => sean
[dob] => 12-20
[parents] => Array
(
[father] => tommy
[mother] => darcy
)
)
입니다 :
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));
}
이 출력을 생성합니다 부모님들. 나는 왜 1이나 2의 깊이가 전혀 표시되지 않는지 모르겠다.
아무도 내가 이해하지 못하는 것을 설명 할 수 있습니까?