Using numbers to access elements in arrays
Trevor DeVore
lists at mangomultimedia.com
Thu Aug 7 13:13:01 EDT 2003
On 8/7/03 Martin Baxter wrote
>
>If you have to modify the data and also need to read the data out in
>numeric order as if the keys were integers in sequence, you can:
>
>put the keys of theArray into akeys
>sort numeric lines of akeys
>repeat for each line i in akeys
> put theArray[i] into something
>end repeat
This works great for one dimensional arrays. I'm wondering if there is a clean way of doing something similar for multi-dimensional arrays. Lets say my array looks like this:
myArray[1,"RecID"]
myArray[1,"Name"]
myArray[6,"RecID"]
myArray[6,"Name"]
myArray[3,"RecID"]
myArray[3,"Name"]
myArray[2,"RecID"]
myArray[2,"Name"]
I can use your technique above to sort the keys with something like:
set itemDelimiter to ","
put keys of myArray into tKeys
sort lines of tKeys ascending numeric by item 1 of each
But when I do my loop:
repeat for each line tRec in tKeys
blah, blah, blah
end repeat
I am looping over each line rather than each key. With each iteration I want to go from key to key rather than line to line. Is there a way to make the repeat structure loop over each key rather than each line? I do a lot of array manipulation in PHP and this is one of the few things I find I miss in Rev.
--
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com
More information about the use-livecode
mailing list