Jump to content


This topic is now archived and is closed to further replies.

Branden Wagner

Currency Conversion (arrays)

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?

                $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($amount > 0)
                                $new = $amount * ${$from}[$to];
                                echo $new;
                                "Invalid Input: Positive numbers only";
                        echo "Invalid Input: use numeric characters only";
                echo "Invalid Request: Please go back and try again";



Share this post

Link to post
Share on other sites


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.