You are here: Re: accessing numerical array index in foreach « PHP Programming Language « IT news, forums, messages
Re: accessing numerical array index in foreach

Posted by Mike Roetgers on 03/22/07 07:09

e_matthes@hotmail.com schrieb:
> 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?
>
> Thanks.
>
Yes, there is a better way.

foreach ($array as $key => $item)
{
blah;
}

You should read through php.net/foreach ;-)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация