I have the below valid JSON that has the key best_images that is causing my problems.
$json_array = {
"best_images":
[{
"id": "1",
"Title": "My Image 1",
"Photographer": "Kate Doe",
"Album": "Album 1",
"Imagefilename": "image1.jpg",
"Year": "2005",
"Size": "1.91 MB"
},
{
"id": "2",
"Title": "My Image 2",
"Photographer": "Jermaine Kavme",
"Album": "Album 2",
"Imagefilename": "image2.jpg",
"Year": "2012",
"Size": "5.13 MB"
},
{
"id": "4",
"Title": "My Image 4",
"Photographer": "Kate Doe2",
"Album": "Album 4",
"Imagefilename": "image4.jpg",
"Year": "2012",
"Size": "1.31 MB"
}
]
}
I want to decode it, and I am using the following method:
$obj = json_decode($json_string, true);
however, when I use the below code to get the keys, I am getting one the best_images key and not the rest.
foreach ($obj as $key => $value)
{
echo $key;
}
How can I get the deeper than the first big key (what is it called actually) to reach the below keys?
Also, how can I separate each inner object so that I can put each one in database row?