RE: Arrays past to functions

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

 



Hello Jacob,

This may be what you're looking for:

<?php

function compute_salestax ($Amount, $Rates = array())
{
	foreach($Rates as $State => $Rate)
	{ 
		$Ret[$State] = $Amount  * ($Rate/100); 
	}
	return $Ret;
}

echo "Payment: " . $payment = 1500;
$taxRates = array("CA" => 5 , "WA" =>  7, "OR" => 8);
$taxresults = compute_salestax ($payment, $taxRates);
foreach($taxresults as $state => $value)
{
 print "<br />Tax = " . sprintf("%01.2f", round($value, 2)) . " in $state.";
}

?>

Browser output results:

Payment: 1500
Tax = 75.00 in CA.
Tax = 105.00 in WA.
Tax = 120.00 in OR.

I hope this helps!!

Jeff White





-----Original Message-----
From: Jacob Bergman [mailto:jbergman@xxxxxxxxxxxxxxxxx] 
Sent: Friday, July 27, 2007 2:07 PM
To: php-windows@xxxxxxxxxxxxx
Subject: RE:  Arrays past to functions

Thanks a bunch guys, I'm out for the day, I will pick this back up on
Monday, have a great weekend.

Jacob Bergman
Network Technician
Pullman School District #267
(509) 432-4012
jbergman@xxxxxxxxxxxxxxxxx

-----Original Message-----
From: Niel Archer [mailto:spam-free@xxxxxxxxxxxxxxxx] 
Sent: Friday, July 27, 2007 11:03 AM
To: php-windows@xxxxxxxxxxxxx
Subject: Re:  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 should work better now.

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);


--
Niel Archer

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

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

-- 
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