Arrays: new and old keys, i
David Bovill
david at vaudevillecourt.tv
Fri Sep 12 17:23:23 EDT 2008
2008/9/12 Mark Wieder <mwieder at ahsoftware.net>
> Trevor-
>
> Thursday, September 11, 2008, 2:20:36 PM, you wrote:
>
>
> > I'm thinking of how PHP behaves. Arrays in PHP know the order that
> > elements were added so that when you use foreach you get the elements
> > in that same order. I always found this very useful when working with
> > arrays in PHP.
>
> AFAIK the order of array keys in "for each" in rev is undefined, so an
> engine change that determined the order wouldn't break any existing
> code.
>
> But I'm sorry to say that I can't think of a situation in which
> chronological order would be helpful. Obviously you've got a scenario
> where this works - could you enlighten me?
Mark I often need the chronological order. Examples of the top I my head
include routines to parse, scripts and create outlines for handlers, or wiki
text and construct outlines for titles, or tree structures where i want to
store the titles and their order matters - based on an outline... in fact
any example where you want to store data in an array for fast retrieval of
that data associated with a line of text, and the order of the titles is not
simply alphabetical but dependent on the orginal order in the document
parsed. I'd probably find it harder to think of examples in which i don't
need the chronological order of array keys.
More information about the use-livecode
mailing list