Hi
I could really do with some help here :)
I am tring to display all of the results from the array without having to write everything out by hand like this
I have been trying to use a for each loop but the array name ($aExchangeRate s) is returned as undefined.
First goal is to display contents of array.
Second step...try to put those values into function to return $result :)
tyvm to anyone who takes pity on a noob
I could really do with some help here :)
I am tring to display all of the results from the array without having to write everything out by hand like this
Code:
echo get_currency(1, GBP); echo "<br>"; echo get_currency(1, USD); echo "<br>"; echo get_currency(2, NZD); echo "<br>";
Code:
foreach ($prices as $key => $value) echo $key.'=>'.$value.'<br />';
Second step...try to put those values into function to return $result :)
tyvm to anyone who takes pity on a noob
Code:
<?php
define('NZD', 'english-nz');
define('GBP', 'english-uk');
define('USD', 'american-english');
function get_currency($iPrice, $original_currency)
{
//-------Associative Array--------------------------//
$aExchangeRates = array (
//-------values in relation to the US dollar--------//
'GBP' => '0.552272',
'USD' => '1',
'NZD' => '1.48695'
);
setlocale(LC_MONETARY, $original_currency);
//-----localeconv()-----//
//-----Returns an associative array containing localized numeric and monetary formatting information-----//
$converting_currency = localeconv();
$iExchangeRate = $aExchangeRates[trim($converting_currency['int_curr_symbol'])];
$iTotal = $iPrice * $iExchangeRate;
$result = $converting_currency['currency_symbol'] . number_format($iTotal, 5);
return $result;
}
echo get_currency(1, GBP);
echo "<br>";
echo get_currency(1, USD);
echo "<br>";
echo get_currency(2, NZD);
echo "<br>";
?>
Comment