Shreyas wrote:
PHP'ers,
I am reading a PHP book which explains foreach and at the end says : *'When
foreach starts walking through an array, it moves the pointer to
the beginning of the array. You don’t need to reset an array before
walking through it with foreach.'*
*
*
*Does this mean - *
*1) Before I navigate the array, foreach will bring the pointer to the
starting key?*
*2) After the first index, it goes to 2nd, 3rd, and nth? *
Regards,
Shreyas
Here is your best reference:
http://php.net/foreach
Look at the two Notes sections on the top of the page.
The first says this:
Note: When foreach first starts executing, the internal array pointer is
automatically reset to the first element of the array. This means that
you do not need to call reset() before a foreach loop.
Basically what you said. But then the second says this
Note: Unless the array is referenced, foreach operates on a copy of the
specified array and not the array itself. foreach has some side effects
on the array pointer. Don't rely on the array pointer during or after
the foreach without resetting it.
--
Jim Lucas
A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php