Wat is the problem with this code.
- Original Message
From: Abhisek Dutta <[EMAIL PROTECTED]>
To: php-windows@lists.php.net
Sent: Tuesday, 31 July, 2007 3:07:06 PM
Subject: Re: [PHP-WIN] Arrays past to functions
Here's what i made:
5,'WA'=>7,'OR'
Here's what i made:
5,'WA'=>7,'OR'=>8);
$states=array('CA','WA','OR');
function calctax($amount, $st)
{
global $taxrate;
global $states;
$tax=$amount*$taxrate[$st];
return $tax/100;
}
$amnt=200;
foreach($states as $st)
{
print "Tax in $st for amount $amnt is ".calctax($amnt, $st);
print "\n";
}
?>
Tax = 120.00 in OR.
I hope this helps!!
Jeff White
-Original Message-
From: Jacob Bergman [mailto:[EMAIL PROTECTED]
Sent: Friday, July 27, 2007 2:07 PM
To: php-windows@lists.php.net
Subject: RE: [PHP-WIN] Arrays past to functions
Thanks a bunch guys, I'm out for the day, I wi
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 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 not
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 y
Niel Archer wrote:
Hi Jacob.
Spotted another problem.
function compute_salestax ($Amount , $State)
{
$taxRate = array("CA" => 5 , "WA" => 7, "OR" => 8);
return $Amount / 100 * $taxRate($State);
}
$payment = 1500;
$locale = 'CA';
print "Tax on $amount in $locale is " . compute_salesta
Hi Jacob.
Spotted another problem.
function compute_salestax ($Amount , $State)
{
$taxRate = array("CA" => 5 , "WA" => 7, "OR" => 8);
return $Amount / 100 * $taxRate($State);
}
$payment = 1500;
$locale = 'CA';
print "Tax on $amount in $locale is " . compute_salestax ($payment , $locale
2007 11:03 AM
To: php-windows@lists.php.net
Subject: Re: [PHP-WIN] Arrays past to functions
Hi Jacob
Sorry, my fault entirely. I wrote it in a hurry after copy/pasting your
example. I didn't change the variable names properly or test it.
I still haven't been able to test, but this sho
Hi Jacob
Sorry, my fault entirely. I wrote it in a hurry after copy/pasting your
example. I didn't change the variable names properly or test it.
I still haven't been able to test, but this should work better now.
function compute_salestax ($Amount , $State)
{
$taxRate = array("CA" => 5 , "W
-
Thanks for the help guys!
Jacob Bergman
Network Technician
Pullman School District #267
(509) 432-4012
[EMAIL PROTECTED]
-Original Message-
From: M. Sokolewicz [mailto:[EMAIL PROTECTED]
Sent: Friday, July 27, 2007 9:3
PROTECTED]
-Original Message-
From: Niel Archer [mailto:[EMAIL PROTECTED]
Sent: Friday, July 27, 2007 9:59 AM
To: php-windows@lists.php.net
Subject: Re: [PHP-WIN] Arrays past to functions
Hi Jacob
try this:
function compute_salestax ($Amount , $State)
{
$taxRate = array("CA&
-
Thanks for the help guys!
Jacob Bergman
Network Technician
Pullman School District #267
(509) 432-4012
[EMAIL PROTECTED]
-Original Message-
From: M. Sokolewicz [mailto:[EMAIL PROTECTED]
Sent: Friday, July 27, 2007 9:34 AM
To: Ja
Hi Jacob
try this:
function compute_salestax ($Amount , $State)
{
$taxRate = array("CA" => 5 , "WA" => 7, "OR" => 8);
return $Amount * $taxRate($state);
}
$payment = 1500;
$locale = 'CA';
print "Tax on $amount in $locale is " . compute_salestax ($payment ,
$locale);
--
// returns 2100
ComputeSalesTax(2000, "LA");
// fails
--
Jarrett M. T. Meyer
http://jarrettmeyer.blogspot.com
http://www.jarrettmeyer.com
- Original Message
From: Jacob Bergman <[EMAIL PROTECTED]>
To: php-windows@lists.php.net
Sent: Friday, July 27, 2007 11:46:19 AM
Subject: [PH
TED]
Sent: Friday, July 27, 2007 8:56 AM
To: PHP Windows List
Subject: Re: [PHP-WIN] Arrays past to functions
You don't really need an array here.
function ComputeSalesTax($Amt, $State)
{
switch ($State)
{
case "CA":
$tax = 1.05;
"LA");
// fails
--
Jarrett M. T. Meyer
http://jarrettmeyer.blogspot.com
http://www.jarrettmeyer.com
- Original Message
From: Jacob Bergman <[EMAIL PROTECTED]>
To: php-windows@lists.php.net
Sent: Friday, July 27, 2007 11:46:19 AM
Subject: [PHP-WIN] Arrays past to functions
Hello all,
I am
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 a
18 matches
Mail list logo