Re: question about a loop in a loop
| From: | Yasuo Ohgaki | Date: | Thu, 29 Mar 2001 02:11:38 +0000 |
| Subject: | Re: question about a loop in a loop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-45988@lists.php.net to get a copy of this message | ||
I think array_intersect() and array_diff() is useful for you..
http://www.php.net/manual/en/function.array-intersect.php
http://www.php.net/manual/en/function.array-diff.php
--
Yasuo Ohgaki
"Institute for Social Ecology" <ise@social-ecology.org> wrote in message
news:Pine.BSF.4.21.0103281453570.14186-100000@flag.blackened.net...
> hi,
>
> I've been driving myself bonkers trying to figure out wy this code block
> does not work as it is supposed to. am hoping that someone on this list
> can shed some light on it.
>
> Whta I am trying to do is evluate two arrays. One array is populated with
> a list. The other array is populated with list items that are found in
> the first array. Array 2 can have either all of the items found in array
> 1, some, or none. I want to create a marker that would tell me which
> items in array 2 are found in array 1 and where.
>
> My code so far:
>
> for argument sake lets say:
>
> $add[$key] ($key defined earlier) is equal to "a, b, e, g"
> $add[$key] is the second array
>
> $$key is the second array, and it equals "a, b, c, d, e, f, g, h, i"
> $$key is the first array.
>
>
> code block:
>
> $x = 0;
> do
> {
> for ($y = 0; $y <= count ($add[$key]); $y++)
> {
> if ($add[$key][$y] == $$key[$x])
> {
> $mark[$x] = $x;
> }
> }
> $x++;
> }while ($x < count ($$key));
>
> So, the idea is that every time $add[$key] at "Y" position is equal to
> $$key at X position, a third array is populated with the location value of X.
>
> but this is not what I am getting spti back at me. $mark is populated
> every iteration of the inner loop regardless if $add[$key][$y] ==
> $$key[$x]
>
> Any suggestions?
>
> thanks!
>
> Michael
>
>
> --
> 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
>