RE: [PHP-GENERAL] Array_walk
| From: | Sam Masiello | Date: | Mon, 26 Jun 2000 19:49:19 +0000 |
| Subject: | RE: [PHP-GENERAL] Array_walk | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-3183@lists.php.net to get a copy of this message | ||
I am going to assume that you are calling array_walk within a loop of some
kind as it is not in your code below. If that is the case, then when you
call array_walk within your loop, you could have something like the
following:
<code>
$grandtotal = 0 ;
while loop {
...
...
$grandtotal = your function where you are calculating the cost ;
}
echo $grandtotal ;
</code>
Sam Masiello
System Analyst
Chek.Com
(716) 853-1362 x289
smasiello@chekinc.com
-----Original Message-----
From: Phil Ahern [mailto:phil@caint.com]
Sent: Monday, June 26, 2000 3:34 PM
To: PHP
Subject: [PHP-GENERAL] Array_walk
Hey All
I have an array of id numbers on which I use the array_walk to search a
database of the for the relevant price and description of the id. What I
want to do is return the total price for all the id numbers in the array.
Anyone know how to do that or maybe a better way. The code is below..
function bookarraycheck($item)
{
global $conn_id;
$result = ifx_query("select title, price from books where bookid =
'$item'",$conn_id);
$r = ifx_fetch_row($result);
ifx_free_result ($result);
echo "<TR><TD WIDTH=\"50%\"
VALIGN=\"TOP\">".$r["title"]."</TD>";
echo "<TD WIDTH=\"50%\" VALIGN=\"TOP\">£
".$r["price"]."</TD></TR>";
$totalcosts += $r["price"];
return $totalcosts;
}
array_walk( $book, 'bookarraycheck' );
Thanks
Phil
Caint.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net