Arrays past to functions
| From: | Jacob Bergman | Date: | Fri, 27 Jul 2007 15:46:19 +0000 |
| Subject: | Arrays past to functions | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-28259@lists.php.net to get a copy of this message | ||
Hello all,
I am learning about passing arrays to functions, and am trying to
create a function that will display a total amount for a price for
several states. Say using CA, WA, and OR, and setting there tax rates
at, whatever, say 5%, 7%, and 8% respectively. I want a function I can
pass the array of states, and tax rates to that will display the total
amount (amount + tax) of say a $1500 purchase. I am trying to use a
switch statement to accomplish this, but I think I may be in over my
head trying to do this with what I have learned so far... Here is the
code I have so far I get 0 every time I run it, try not to laugh... :-)
Thanks guys.
$State = array ("CA" , "WA" , "OR");
function compute_salestax ($Amount , $State)
{
switch ($State)
{
case "CA" :
$Rate = "1.05";
break;
case "WA" :
$Rate = "1.07";
break;
case "OR" :
$Rate = "1.08";
break;
}
global $Rate;
$Truetax = ($Amount * $Rate);
echo "$Truetax <br />";
}
$Amount = 1500;
compute_salestax($Amount , $State);
Jacob Bergman
Network Technician
Pullman School District #267
(509) 432-4012
jbergman@psd267.wednet.edu