Using numbers to access elements in arrays

Trevor DeVore lists at mangomultimedia.com
Fri Aug 8 09:33:00 EDT 2003


On 8/8/03 Martin Baxter wrote

>I heartily agree that more array flexibility would be welcome in
>Revolution, and PHP does "spoil us rotten" in that respect.
>
>In the case you cite, just sorting the keys by item 1 might not necessarily
>end up with the result you assume above.
>To get that reliably I think you would need to have 2 levels of sorting,
>the first numeric and the second alphanumeric..
>Alternatively you might address the problem inside the loop.
>
>Assuming the array keys are known to be "dimensionally consistent"
>throughout, my first instinct would be to try something like the following
>(untested) :
>
>## do your keysort by item 1
>put empty into bunchHolder
>put 1 into bunchCounter
>repeat for each line tRec in tKeys
>  if bunchCounter = 1 then
>      put myArray[tRec] into bunchHolder
>      put 2 into bunchCounter
>  else if bunchCounter = 2 then
>      put myArray[tRec] into line 2 of bunchHolder
>      sort lines of bunchHolder
>      # do what you need to do
>      put 1 into bunchCounter
>  end if
>end repeat

Thanks Martin.  I actually ended using something similar to what you mentioned above.  I didn't do the sort on the second key as I was looking at the value of it within the looop rather than sorting twice and using a var such as bunchCounter.  For this method (which is probably much slower with lots of data) sorting on this first key seems to work out.

Thanks,

-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com



More information about the use-livecode mailing list