First off, please try to refrain from cross-posting, especially to that 
degree.

I'm not sure I interpreted the your intentions correctly. If not, could you 
try to be a little more precise in saying what you _want_ the code to do?

The first thing that jumps out at me is in the function getTax. Shouldn't it 
be getTax($value)? As you have it, value will be unset (search for variable 
scope in the manual). I think this may be what you're going for:

function getTax($value) {
        return ($value * 0.065);
}

Next, the list construct will only work with numeric arrays, not associative 
ones. In other words, it has to look like array('one', 'two'), not 
array('one' => 'two', 'three' => 'four')

Next the way you have it set up, $mypurchases can only contain one set of 
three items. I don't get the logic of how car, pencil, and book map to $key, 
$value, and $tax.... Maybe you were going for

$mypurchases = array(
        'car' => 15000,
        'pencil' => 1,
        'book' => 14.95);
$total = 0;
echo '<table><tr><td>Item</td><td>Cost</td>';
echo '<td>Tax</td><td>Running Total</td></tr>';
foreach ( $mypurchases as $key => $value) {
        $total += $value + ($tax = getTax($value));
        // assuming you want the table in HTML, since you have a <br/>...
        echo "<tr><td>{$key}</td><td>{$value}</td>";
        echo "<td>{$tax}</td><td>{$total}</td></tr>\n";
}
echo '</table>';

???

I'm going to ignore the getBalance function because I don't think it's 
required. But you realize your declaring a static variable, then trying to 
assign a different value to it on the very next line?




On Friday 21 November 2003 01:56 am, Sara Daugherty wrote:
> I could use a little help. click on the link to see my php code for a
> project that creates an array with a list or items and their cost and
> calculates tax by using a function called getTax() and also creates a
> balance by adding the cost plus the tax in a second function called
> getBalance(). I must also create a table where the cells automatically
> load so the end result looks like this.
> http://www.areawebdirectory.net/taxtable2.txt
>
>
> Item          Cost          Tax          Running Total
> Car          10000.00    600          10600.00
> Pencil       1.00           .06            10601.06
> Book        14.95         .097         10616.98
>
>
> I cant seem to first be able to declare my array and succeed at naming
> the key as item and the value as price. I have attempted to use
> variations of the following with no success.
>
> $items = array (
>     0 => array ("item"=>"car","price"=>15000, "tax"=>.065 ),
>     1 => array ("item"=>"pencil","price"=>1, "tax"=>.065 ),
>     2 => array ("item"=>"book","price"=>14.95, "tax"=>.065)
> );
>
> Without being able to declare the key as item and the value as price I
> am not sure how to pass these items into my function and I am riddled
> with error messages. I think my base problem is to either fix how I am
> declaring the array so I may reference "item" and "price" as I am now
> doing in my functions or learn how to change the functions accordingly.
>
> I am also pretty sure that my functions are not quite right. I am also
> not sure how to link the right answers to get my table to print as above.
>
> Please note that I have included a while loop after my array just to
> prove that my array is working. It is needed part of my program. I also
> have given each cell in my table some text just so I can find them when
> I have figured out how to create the right reference links.
>
> I am sorry that I need as much help with this. Sadly I have been at this
> for almost two weeks trying to solve it.
>
> Thanks,
> Sara

-- 
Evan Nemerson
[EMAIL PROTECTED]
http://coeusgroup.com/en

--
"Truth, like gold, is to be obtained not by its growth, but by washing away 
from it all that is not gold. "

-Leo Nikolaevich Tolstoy

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

Reply via email to