I have a url that returns a json. I want to loop through to get each of the values in the json.
This is what my json looks like.
{"error":false,
"message":"Request orders successfully completed",
"orders":[{
"oid":505,
"uid":234,
"total_amount":"143.99000"
},
{
"oid":506,
"uid":234,
"total_amount":"1.19000"
}]
}
My PHP code
$getOrdersUrl = file_get_contents("https://apiurl?last_id=504");
$json = json_decode($getOrdersUrl, true);
if(!empty($json)){
foreach($json as $val)
{
$oid = $val['orders'][0]['oid'];
$uid = $val['orders'][0]['uid'];
$total_amount = $val['total_amount'];
echo $oid;
}
}else{
echo "No Data to fetched to fetch for <br>";
}