You are here: Re: [PHP] Foreach problem. « PHP « IT news, forums, messages
Re: [PHP] Foreach problem.

Posted by Richard Lynch on 02/10/05 21:26

Mirco Blitz wrote:
> HI,
> I am really confused.
> I have an array, that looks like this:
>
> print_r($elementsarr) = Array ( [0] => knr [1] => subject [2] => title [3]
> => kat [4] => pages [5] => access [6] => dofile [7] => MAX_FILE_SIZE [8]
> =>
> pdf [9] => dolink [10] => link [11] => erstam [12] => endless [13] => from
> [14] => until [15] => openbem [16] => history [17] => closedbem [18] =>
> [19]
> => b [20] => br [21] => bw [22] => bay [23] => h [24] => hb [25] => hh
> [26]
> => mv [27] => n [28] => nw [29] => rp [30] => s [31] => sa [32] => sh [33]
> => sn [34] => t [35] => bund )
>
> Now i try to work with this array in a foreach.
>
> foreach($elementsarr as $key=>$tmp);
> {
> echo "$key=>$tmp<br>";
> }
>
> Now the result of that is:
>
> 35=>bund
>
> Ist not the first time i work with foreach. But it is the first time it
> just
> returns the last value.
>
> Do you have an idea why?

Perhaps you need to use http://php.net/reset

You see, when you do foreach or each or any of those, there is an
"internal" setting in the array that is altered to keep track of where you
are. Kind of like a big "You are here" arrow inside the guts of the
array.

If you've gone through the whole thing already, you have to reset the
internal point back to the beginning.

"Be Kind, Rewind!"

TIP:
Put a 'reset' before anything that loops the array. That way, if you add
something before it that loops through, it can't cause the side-effect of
a bug in your other code. Just a good habit to form.

--
Like Music?
http://l-i-e.com/artists.htm

 

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

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