I usually work a lot with 2D arrays. Since I've had some trouble traversing them correctly maybe someone out there also experienced those problems and can use this one.
It's based on a 2D-array called $array[$x][$y]. At some (but not necessarily all) (x,y) there is a value I want to reach. Note that I do not know beforehand the ranges of $x or $y (that is their highest and lowest values).
while (list ($x, $tmp) = each ($array)) {
while (list ($y, $val) = each ($tmp)) {
echo "$x, $y, $val";
}
}
The answer for each (x,y) pair can thus be (providng, of course those values where in your array beforehand):
1, 1, 2
2, 2, 0
3, 1, 1
5, 2, 2
5, 1, 2
Note that only the (x,y) pairs with a corresponding value is shown.
Hang in there
Jon Egil Strand
NTNU