I am getting some exchange rate data and would like to access the variable outside of the for loop. My current code only results in:
1: 0.82910
but my expected result is:
1: 0.82910
2: 0.82910
I am wondering why this variable is not accessible outside of the loop and how can I make it accessible?
My code (Sorry if the code is bad, Im new to PHP)
$vExchaRates = file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
$xml = simplexml_load_string($vExchaRates);
for ($i = 1; $i <= 32; $i++) {
if ($xml->Cube[0]->Cube[0]->Cube[$i]->attributes()->currency == "GBP") {
$vGBPERate = $xml->Cube[0]->Cube[0]->Cube[$i]->attributes()->rate;
echo "1: " . $vGBPERate . "\r\n";
}
}
echo "2: " . $vGBPERate;
Thank you for any help you can provide.
. "\r\n"to the secondecho?