I believe foreach also works on a copy basis, not a pointer or reference. So
if you try and alter the array you are foreach'ing it won't work as
expected.
For instance this:
$array = array("var1", "var2", "var3");
foreach ($array as $val)
{
if ($val == "var2")
{
$val = "changed2";
}
}
print_r($array);
Will show you that no change to $array has occurred.
It's basically the same as list(), but it's worth noting.
Other than backwards compliance, I've never used the list/each way of doing
it. Never really had a reason too...I think it basically just comes down to
user preference.
--
Plutarck
Should be working on something...
...but forgot what it was.
"Joe Stump" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> What are the differences in these? I know with while() you have to reset()
the
> array afterwards, but foreach() you don't. Also foreach() appears to be
quite
> a bit faster.
>
> My main question is there ANY difference in how these two loop through the
> array.
>
> --Joe
>
>
>
>
/***************************************************************************
***\
> * Joe Stump - PHP/SQL/HTML Developer
*
> * http://www.care2.com - http://www.miester.org -
http://gtk.php-coder.net *
> * "Better to double your money on mediocrity than lose it all on a
dream." *
>
\***************************************************************************
***/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]