Re: Arrays past to functions
| From: | Niel Archer | Date: | Fri, 27 Jul 2007 19:40:02 +0000 |
| Subject: | Re: Arrays past to functions | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-28275@lists.php.net to get a copy of this message | ||
Hi
> hi Niel,
>
> I believe Jacob wanted to know how he could calculate the tax for _all_
> states passed in as an array in one go. Yours simply gives it for 1
> State ("locale"). Other than thatm $taxRate($state) translates to
> Array($state) which gives an E_FATAL_ERROR obviously. I assume you meant
> to say $taxRate[$State].
After re-reading Jacob's post I have to agree I misunderstand. Here's a
better answer to his request.
// Create array of locales we want tax for
$locales = array("CA", "OR");
$payment = 1500;
ShowSalesTax($payment, $locales);
function ShowSalesTax($Amount , $States)
{
//aray of states and their rates
$StatesRates = array("CA" => 5 , "WA" => 7, "OR" => 8);
foreach($States as $state):
print "Tax on $Amount in $state is " . $payment / 100 * $StatesRates[$state] .
"\n";
endforeach;
}
Obviously, it's only an example and needs refining.
--
Niel Archer