Hello everyone. I'm a self learner that is very new to programming. I'm trying to print out the value of ["mid"] from a json_decode variable in the code shown below:
I'm trying to use for each to access the value of "mid'. using foreach function. I know I'm not doing it the right way. please help me or show me an easy was to go around it.
/////the json resopnd form the url is :
{"terms":"http://www.xe.com/legal/dfs.php","privacy":"http://www.xe.com/privacy.php","from":"USD","amount":1.195,"timestamp":"2021-02-09T16:52:00Z","to":[{"quotecurrency":"NGN","mid":454.6559871014}]}
/////////////////////////////////////////////////
<?php
$auth = base64_encode("username:password");
$context = stream_context_create([
"http" => [
"header" => "Authorization: Basic $auth"
]
]);
$homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context );
$json = json_decode($homepage, TRUE);
foreach ($json as $price){
echo $price['mid'];
};
?>