Re: need help with foreach()
| From: | Fredrik de Vibe | Date: | Mon, 10 Mar 2003 00:40:19 +0000 |
| Subject: | Re: need help with foreach() | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26212@lists.php.net to get a copy of this message | ||
haloplayer@hotmail.com (David Rice) writes:
> Hey thank's for the ideas but neither of them work, doh...
> Okay fredrik I know your idea won't work cos list only works with
> numericaly indexed arrays, both the arrays that i am using are indexed
> by date.
You really had me wondering there for a moment. I've done this dozens
of times and list() does work with other than numerical values.
> (it produces a parse error when run)
Ok, I hadn't tested the code. For some reason you have to group $t /
$staff[$d] in parantheses, why I really don't know, it shouldn't be
necessary.
> =====================
> while(list($d, $t) = each($tips)){
$res = ($t / $staff[$d]);
^ ^
> // Do what you need with $res ...
> }
> =====================
The code below is tested and works.
---
$tips = array("foo" => "bar",
"bar" => "foo");
$staff = array("foo" => "foobar",
"bar" => "barfoo");
while(list($d, $t) = each($tips)){
printf("%s - %s - %s<br>\n", $d, $t, $staff[$d]);
}
--
--Fredrik
New systems generate new problems.