note 19004 added to function.each

From: Date: Wed, 13 Feb 2002 09:10:36 +0000
Subject: note 19004 added to function.each
Groups: php.notes 
Request: Send a blank email to php-notes+get-26539@lists.php.net to get a copy of this message
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 -- http://www.php.net/manual/en/function.each.php http://master.php.net/manage/user-notes.php?action=edit+19004 http://master.php.net/manage/user-notes.php?action=delete+19004 http://master.php.net/manage/user-notes.php?action=reject+19004

« previous php.notes (#26539) next »