Here is my php code with json formatted string:
<?php
$string='{"items": [
{
"address":"W 7th Ave"
},
{
"address":"W 8th St"
}
]}';
$json = json_decode($string, true);
foreach ($json as $key => $value){
echo "$key: $value\n";
};
?>
I want to learn how to parse/output json string into something I can show in html or put into database .. however i am stuck on something that is prob very simple but I've spent most of the morning trying to figure out.
What I want to understand is why the results of my code above gives me the following result:
"items: Array"
And not what I want/expect to get:
"items: W 7th Ave"
"items: W 8th St"
What am i missing? Isn't "Address" the next "level" down from "Item" in the array?
foreach
part,$json
returnsarray
. – Tarik Jul 26 '11 at 17:03