Re: Arrays past to functions
| From: | M. Sokolewicz | Date: | Fri, 27 Jul 2007 22:57:56 +0000 |
| Subject: | Re: Arrays past to functions | ||
| References: | 1 2 3 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-28276@lists.php.net to get a copy of this message | ||
Niel Archer wrote:
HiI 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) - Tulhi 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