Jump to content


Photo

Currency Conversion (arrays)


  • Please log in to reply
No replies to this topic

#1 Branden Wagner

Branden Wagner
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts

Posted 05 October 2006 - 11:57 PM

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?

<?
        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";
        }

?>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users