annoying for-loop/hash-index issue
| From: | Andrew A. Neuschwander | Date: | Tue, 09 May 2000 23:59:25 +0000 |
| Subject: | annoying for-loop/hash-index issue | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-14703@lists.php.net to get a copy of this message | ||
Hi all,
I ran into something really annoying while hacking up a php graph class
method. It's not exactly php specific, but I was wondering how often
people hit this, my code is something like this:
$sets = array($var1, $var2, $var3);
for (reset($sets); $key=key($sets); next($sets)) {
//do some work with $key here;
}
Because the first index of $sets is 0, $key=key($sets) returns 0 and the
loop is never entered. I was annoyed because most (vector) arrays start
with 0. Granted, a while loop makes more sense on a pure vector array,
but if you ever end up with a "0" as a hash index, kiss your for loop
goodbye.
Anyway, just my $0.02
Andrew N.
---
RedHat Linux 6.2 ... The Ultimate NT Service Pack
Andrew A. Neuschwander http://neuschwander.org/
drender@bigsky.net andrew@neuschwander.org