Posted by Kim Andrι Akerψ on 03/21/07 17:32
e_matthes@hotmail.com wrote:
> Hello everyone,
>
> I have no trouble looping through an array using foreach. To keep
> track of the index, I set a variable before the loop and increment it
> in the loop:
>
> $index = 0;
> foreach ($array as $item) {
> blah;
> $index++;
> do something that requires knowing the index of the current item;
> }
>
> Is there a better way to access that index value?
You might get a better result with this:
foreach ($array as $index=>$item) {
// blah;
// do something else;
}
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Navigation:
[Reply to this message]
|