question about a loop in a loop
| From: | Institute for Social Ecology | Date: | Wed, 28 Mar 2001 23:03:51 +0000 |
| Subject: | question about a loop in a loop | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-45956@lists.php.net to get a copy of this message | ||
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