The PHP function json_decode has a depth parameter, where you can specify how deep it will repeat. But the following code:
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)); }
Produces this conclusion:
----------------- depth: 1 ----------------- depth: 2 ----------------- depth: 3 Array ( [name] => sean [dob] => 12-20 [parents] => Array ( [father] => tommy [mother] => darcy ) )
What I expect is depth 1 to show "name" and "ext", and depth 2 to show parents, too. I do not understand why a depth of 1 or 2 does not display anything at all.
Can someone explain to me what I don't understand?
source share