# 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]#

## Multidimensional Arrays

ColdFusion supports dynamic multidimensional arrays. When you declare an array with the ArrayNew function, you can specify up to three dimensions. However, you can increase an array's dimensions by nesting arrays as array elements:

    <CFSET myarray=ArrayNew(1)>
    <CFSET myotherarray=ArrayNew(2)>
    <CFSET biggerarray=ArrayNew(3)>

    <CFSET biggerarray[1][1][1]=myarray>
    <CFSET biggerarray[1][1][1][10]=some_value>
    <CFSET biggerarray[2][1][1]=myotherarray>
    <CFSET biggerarray[2][1][1][4][2]=some_value>

    <CFSET biggestarray=ArrayNew(3)>
    <CFSET biggestarray[3][1][1]=biggerarray>
    <CFSET biggestarray[2][1][1][2][3][1]=some_value>