I have the following example JSON:
{
productAPI: {
status: 200,
message: "OK",
version: 3,
products: {
grouped: {
matches: 773949,
groups: [
{
doclist: {
start: 0,
numFound: 385957,
docs: [
{
merchant: "Amazon",
currency: "GBP"
}
]
},
doclist: {
start: 0,
numFound: 885957,
docs: [
{
merchant: "Ebay",
currency: "GBP"
}
]
}
There will be multiple Merchant names I want to print but getting blank result (I am quite new to JSON parsing)
Here's what I'm trying:
$prodList=$prodList['productAPI']['products']['grouped']['groups']['doclist']['docs'];
foreach ($prodList as $element){
echo $element['merchant'];
}
Is this the correct method?
UPDATE
As has been correctly pointed out (I didn't add enough example) 'groups' is an array, so, I've changed to the following but still no joy:
$prodList=$prodList['productAPI']['products']['grouped']['groups'];
$i=0;
foreach ($prodList as $element){
echo $element[$i]['doclist']['docs']['merchant'];
$i++;
}