You are here: Re: how to save/restore current array position? « PHP Programming Language « IT news, forums, messages
Re: how to save/restore current array position?

Posted by Shelly on 07/24/05 17:28

"Magnus Warker" <wagner@abwesend.de> wrote in message
news:dc05i8$3bj$04$1@news.t-online.com...
> Hi,
>
> I want to traverse an (associative) array, starting from its current
> position, until a certain element is reached. Then, in certain cases, I
> want to be able to reset the current position of the array to the one that
> we had before touching the array.
>
> I. e., i need something like funcctions getpos and setpos:
>
> ----------
>
> $pos = getpos ($list);
>
> do
> {
> $item = current ($list);
> $name = key ($list);
>
> next ($list);
> } while (!isWanted ($item));
>
> setpos ($list,$pos);
>
> ----------
>
> What I really need in the above example is:
> Check, if we *could* get another wanted item from the list, but actually
> leave the list (its current position) untouched.
>
> Any ideas?
>
> Many thanks,
> Markus
>

Reverse the while and do so that it is a pre-test? As for the setpos and
getpos, there are many ways.

C style:
(1) Set a session variable with the value and read the value.
(2) Pass the variable to the next page and use $_GET

OO style:
encapsulate in the class as a variable in the class. The obect then has
the value of "pos", and getpos and setpos are merely accessor and mutator
methods of the class.

I hope that helps.

Shelly

 

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

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