I'm using CF 10. As a script is running, I am creating an array containing distinct values that represent a single vehicle. I'm initializing the array at the top of my script using
<cfset myArray = ArrayNew(1)>
Then as I am running my script I'm appending to it using...
<cfset temp = ArrayAppend(myArray, myQuery.VIN)>
This all works fine, but what I want to do is after each section in the script is reached, I want to update any VINS in my current section query so that they are an array of values. So the Array that was..
[1]["VIN NUMBER 123"] [2]["VIN NUMBER 456"]
becomes...
[1]["VIN NUMBER 123"]["VALUE1"] ["VALUE2"] ["VALUE3"] [2]["VIN NUMBER 456"]["VALUE2"]
I thought I could do something like this...
<cfset vindex = ArrayFind(myArray,vinToFind)>
<cfif NOT IsArray('myArray[vindex]')>
<cfset myArray[vindex] = ArrayNew(1)>
</cfif>
<cfset temp = ArrayAppend(myArray[vindex],valueToAppend)>
but in the end, my array is still one dimensional. What am I doing wrong?
I recommend an array of arrays as suggested by @ale.
Here are some tips:
ArrayAppend(1)
can be written as[]
.ArrayAppend(myArray, value)
can be written asmyArray.add(value)
.ArrayAppend
as it will always returntrue
. Just go with<cfset ArrayAppend(myArray, value)>
.IsArray
expects a variable, not a string.IsArray("myArray")
will always returnfalse
whileIsArray(myArray)
would returntrue
.The above code using array literals and the
add
method.