I have this function, historicalBootstrap, which I want to use to put three different datasets into a page:
$years = array(
date('Y-m-d', strtotime('1 year ago')). ".json",
date('Y-m-d', strtotime('2 years ago')). ".json",
date('Y-m-d', strtotime('3 years ago')). ".json"
);
function historicalBootstrap($years, $id){
for($i = 0; $i < 3; $i++){
$date = $years[$i];
$i = curl_init("http://openexchangerates.org/api/historical/{$date}?app_id={$id}");
curl_setopt($i, CURLOPT_RETURNTRANSFER, 1);
$jsonHistoricalRates = curl_exec($i);
curl_close($i);
$i = json_decode($jsonHistoricalRates);
echo '<script>_'. $i . 'historical = '. json_encode($historicalRates) . ' ; ' . '</script>';
}
}
historicalBootstrap($years, $appId);
It seems I can use this approach to make one request, e.g. outside of the function block. Why is it that when I abstract this approach into the historicalBootstrap function that it fails? I am expecting three (_0 = ... , _1 = ... , _2 = ...) bootstrapped scripts.
Thank you.