On Thu, 2005-02-10 at 14:26, Richard Lynch wrote: > 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!" >From the PHP docs: 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. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php