Note the line that says "This line displays nothing."
How would I display the age value there?
I'm trying to figure out how to use json.
<?php
$small_test = array(
'name' => array('John', 'Smith'),
'age' => 27,
'sex' => 0,
'height' => 180.53,
'is_human' => true,
'string' => 'Hello'
);
$big_test = array(
array(
'name' => array('John', 'Smith'),
'age' => 27,
'sex' => 0,
'height' => 180.53,
'is_human' => true,
'string' => 'Hello'
),
array(
'name' => array('Green', 'Alien'),
'age' => 642,
'sex' => null,
'height' => 92.21,
'is_human' => false,
'string' => '?????!'
)
);
$test1 = json_encode($big_test);
print $test1;
$obj2 = json_decode($test1);
print "<br />TEST1 " . $obj2->{'age'} . "<br />"; // This line displays nothing. How can I fix it?
print_r($obj2);
$test2 = json_encode($small_test);
print $test2;
$obj2a = json_decode($test2);
print "<br />TEST2 " . $obj2a->{'age'} . "<br />"; // This shows 27
print_r($obj2a);
?>