User Guide
Chapter 9: Handling Complex Data with Structures 105
ColdFusion dynamic 2D array
A ColdFusion 2D array is actually a 1D array that contains a series of additional 1D
arrays. Each of the arrays that make up a column can expand and contract
independently of any other column.
The following terms will help you understand subsequent discussions of ColdFusion
arrays:
• Array dimension — The relative complexity of the array structure.
• Index — The position of an element in a dimension, ordinarily surrounded by
square brackets: my1Darray[1], my2Darray[1][1], my3Darray[1][1][1].
• Array element — Data stored in an array index.
The syntax
my2darray[1][3]="Paul" is the same as saying 'My2dArray is a two
dimensional array and the value of the array element index [1][3] is "Paul".'
Dynamic arrays expand to accept data you add to them and contract as you remove
data from them.
Creating an Array
In ColdFusion, you declare an array by assigning a variable name to the new array as
follows:
<CFSET mynewarray=ArrayNew(
x
)>
where x is the number of dimensions (from 1 to 3) in the array you want to create.
Once created, you can add data to the array, in this case using a form variable:
<CFSET mynewarray[3]=Form.emailaddress>
Data in an array is referenced by index number, in the following manner:
#My1DArray[
index1
]#<BR>
#My2DArray[
index1
][
index2
]#<BR>
#My3DArray[index1][index2][index3]#