I am having a hard time getting the value of an array in JSON to php.
Here is the JSON format I'm trying to retrieve:
{
"products": [
{
"product_id": 18647,
"model_code": "CVADA-M702-Black-2GEN"
}
{
"product_id": 14343,
"model_code": "CDEP-Q123-Blue-3GEN"
}
]
}
and I'm trying to retrieve it like this but to no avail:
$response = json_decode($json_response, true);
foreach($response as $res)
{
print $res->products->product_id;
}
It works though if I'm only trying to input a singl output:
$response = json_decode($json_response, true);
print $response['products'][0]['product_id'];
So, can anyone help me how to properly retrieve JSON value to php?