SV: [PHP4BETA] Trying to be elegant...
| From: | Johan Ekenberg | Date: | Sun, 05 Mar 2000 23:28:01 +0000 |
| Subject: | SV: [PHP4BETA] Trying to be elegant... | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-11546@lists.php.net to get a copy of this message | ||
> > while (list(,$val) = each(array("a", "b", "c"))) {
> > print "$val<BR>\n";
> > }
> What the code above looks like it says is:
> 1. Create an array with elements 'a', 'b', and 'c';
> 2. Get the first element;
> 3. Assign that element to $val;
> 4. Print $val;
> 4. goto 1;
>
> The each() is evaluated on every loop, as you intended, but so is the
> array(), which I don't believe you want.
You're right of course.
I'm just getting to used to writing stuff like:
print for (1..10);
in Perl.
foreach(array() as $val) is good, I didn't think about
that actually entering the PHP world through version 4.
Thanks!
/Johan Ekenberg