Jump to content

Currency Conversion (arrays)


Branden Wagner

Recommended Posts

OK, so this is just for fun... why? i have no clue...
anyway what is the best way to do the arrays/variables for the conversions
the USD is the only one that works correctly.. because of the associative array.
to finish i just need to do the same to the rest of them, but i was hoping there was a better way to do this.
any suggestions?

[code]
<?
        if(isset($_REQUEST['amount']))
        {
                $amount = $_REQUEST['amount'];
                $to = $_REQUEST['to'];
                $from = $_REQUEST['from'];

                // US, Yen, Euro, British Pound, Peso
                $USD = array("USD" => "1","JPY" => "0.0085","EUR" => "1.27","GBP" => "1.87" ,"MXN" => "0.09");
                $JPY = array("117.50","1","150.0","221.52","10.76");       
                $EUR = array("0.79","0.0067","1","1.48","0.07");
                $GBP = array("0.53","0.0045","0.68","1","0.05");
                $MXN = array("10.98","0.0934","13.94","20.58","1");

                if(is_numeric($amount))
                {
                        if($amount > 0)
                        {
                                $new = $amount * ${$from}[$to];
                                echo $new;
                        }
                        else
                        {
                                "Invalid Input: Positive numbers only";
                        }
                }
                else
                {
                        echo "Invalid Input: use numeric characters only";
                }
        }
        else
        {
                echo "Invalid Request: Please go back and try again";
        }

?>

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.