Order in != order out
Thursday, July 24th, 2008Because arrays in Coldfusion are based off of the vector collection in Java, they don’t always maintain their order in every instance. If you use ArrayToList(), the order of the list returned will come out in whatever random order it happens to be stored in memory. If you want a quick demonstration, use the following code:
<cfdump var="#ListToArray(StructKeyList(Variables))#" />
Just keep refreshing the page and you will see the order of the array keep changing.
To get around the weirdness with this, try using the java vector’s methods instead of CF’s array methods. Just remember that the java methods use zero based arrays (versus CF using one based arrays).
Edit: That example isn’t entirely accurate. Scope variables are based off of abstract maps, but the concept is the same.