Re: need help with foreach()

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

 



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.

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux