Source Code:
(back to article)
<?php // Assigning JSON encoded string to a PHP variable $json = '{"George":63,"David":75,"Harold":60,"Clark":90}'; // Decode JSON data to PHP associative array $arr = json_decode($json, true); // Loop through the associative array foreach ($arr as $key => $value) { echo $key . "=>" . $value . "<br>"; } echo "<hr>"; // Decode JSON data to PHP object $obj = json_decode($json); // Loop through the object foreach ($obj as $key => $value) { echo $key . "=>" . $value . "<br>"; } ?>
Result:
Report an issue