Re: Arrays past to functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Niel Archer wrote:
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


I must say, you're the first (and only) person I've ever seen using foreach(): endforeach in PHP. As far as I know, most people use curly-bracers (in this case), I'm sure most people wouldn't even know this was possible (I had to look it up in the manual, and it's only in a single note that this is mentioned)

- Tul

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux