Source Code:
(back to article)
<?php // Assigning JSON encoded string into a PHP variable $json = '{"George":63,"David":75,"Harold":60,"Clark":90}'; // Decode JSON data to PHP associative array $arr = json_decode($json, true); // Accessing values from the associative array echo $arr["George"]; // Output: 63 echo $arr["David"]; // Output: 75 echo $arr["Harold"]; // Output: 60 echo $arr["Clark"]; // Output: 90 // Decoding JSON data to a PHP object $obj = json_decode($json); // Access values from the returned object echo $obj->George; // Output: 63 echo $obj->David; // Output: 75 echo $obj->Harold; // Output: 60 echo $obj->Clark; // Output: 90 ?>
Result:
Report an issue