Looks like this may already be answered, but I just got around to playing with this. My solution is very similar, but maybe a bit more streamlined, if you are still just trying to add blank rows for output purposes.
<cfset Test = ArrayNew(2)>
<cfset Test[1][1] = 'Sacramento'>
<cfset Test[1][2] = 'C001'>
<cfset Test[2][1] = 'Los Angles'>
<cfset Test[2][2] = 'C002'>
<cfset Test[3][1] = 'New York'>
<cfset Test[3][2] = 'C003'>
<cfset Test[4][1] = 'Seattle'>
<cfset Test[4][2] = 'C004'>
<h3>Dump Test Array</h3>
<cfdump var="#Test#">
<h3>Output Row 4</h3>
<cfoutput>#Test[4][1]# #Test[4][2]#</cfoutput>
<cfset ArrayInsertAt(Test,3,ArrayNew(1))>
<h3>Dump Test Array After new row added</h3>
<cfdump var="#test#">
<h3>Output Row 4</h3>
<cfoutput>#Test[4][1]# #Test[4][2]#</cfoutput>
The only real difference then the other example, is I don't bother creating a blank placeholder array. Just put the ArraNew(1) function as the third parameter of the ArrayInsertAt function. This creates a blank new array at the new position. Then, if you later decide you need to put data here, you can just use simple assignment.
<cfset Test[3][1] = first value>
<cfset Test[3][2] = second value>
ect.
What took me a little to get my head around, when I first learned Cold Fusion Arrays, is that, when you have a two dimension Array, it does not have to be a grid or table. It is more proper to visualize it as a one diminsion array, that each element contains individual one diminsion arrays. Thus you can have different size arrays at each element. Something like this.
1 : Apples Oranges Peaches
2 : Joe Sally Jim Paul Mary Ringo George
3 : 1 2 3 4 5 6 7 8 9 10
4 : Cool
5 : A B C D E F G H I J K L M N O P Q
Thus you have a 3 element sub-array in position 1, a 7 element sub-array in position 2, a 10 element sub-array in position 3, a 1 element sub-array in position 4 and finally 17 element sub-array in position 5.
This is powerfull stuff, because each sub-element can contain another level of array, thus you can create truely mind boggeling array demeinsions, only limited by memory, performance and sanity.
If you wanted an 11 dimension array {StringTheoryArray[2][3][1][5][7][8][1][9][17][22][4]}, this is perfectly leagle and allowed. May not be advisable, but you can do it.
[Todays Threads]
[This Message]
[Subscription]
[Fast Unsubscribe]
[User Settings]
- Re: Inserting rows into a 2d array DougF
- RE: Inserting rows into a 2d array Dave Watts
- Row Number variable brob
- RE: Row Number variable Raymond Camden
- Re: Inserting rows into a 2d array DougF
- RE: Inserting rows into a 2d array Ian Skinner
- RE: Inserting rows into a 2d array Dave Watts
- Re: Inserting rows into a 2d array DougF
- RE: Inserting rows into a 2d array Joe Eugene
- Re: Inserting rows into a 2d array Ian Skinner
- RE: Inserting rows into a 2d array Dave Watts
- Re: Inserting rows into a 2d array DougF
- Re: Inserting rows into a 2d array Ian Skinner
- Re: Inserting rows into a 2d array DougF
- RE: Inserting rows into a 2d array Ian Skinner