I was working with a 2D array this past week and no matter what I tried, I was not able to access the data elements in the array. Coldfusion kept returning "Complex/simple value" errors or index of elemnet in position 1, etc..
I moved on a found a different method using a struct, but I am curious as to why I could not get the correct index.
I was trying to read in a text file:
<cfset myarr = arraynew(2) />
<cffile action="read" file="#filepath#" variable="filedata" />
<cfloop list="#filedata#" index="line" delimiters="#chr(13)##chr(10)#">
<cfset line = trim( line ) />
<cfif line contains "routing number">
<cfset arrayappend( myarr[1], listlast( line, ":" )) />
<cfelseif line contains "account number">
<cfset arrayappend( myarr[2], listlast( line, ":" )) />
</cfif>
<cfloop index="j" from="1" to="#arraylen( myarr )#" step="1">
<cfoutput>
#listgetat( myarr[line][j] )#
</cfoutput>
</cfloop>
</cfloop>
Now, if I dump out my array, the array looks correct
array
1
1 999999999
2 111111111
array
2
1 12345678
2 987654321
However, the nested loop above does not get the correct position of the element in the index and I do not understand why.
Thanks for any help or insight you can provide.