User Guide

Basic Array Techniques 119
Creating 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 arrays 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]=3>
<cfset biggerarray[2][1][1]=myotherarray>
<cfset biggerarray[2][1][1][4][2]="reality">
<cfset biggestarray=ArrayNew(3)>
<cfset biggestarray[3][1][1]=biggerarray>
<cfset biggestarray[3][1][1][2][3][1]="This is complex">
Adding elements to an array
You can add elements to an array by defining the value of an array element:
<cfset myarray[5]=form.variable>
But you can also use a number of array functions to add data to an array. You can use
the following functions:
When you insert an array index with
ArrayInsertAt, all indexes to the right of the
new index are recalculated to reflect the new index count.
For more information about these array functions, see the CFML Reference.
Note
Because ColdFusion arrays are dynamic, if you add or delete an element from the
middle of an array, higher-numbered index values all change.
Referencing elements in dynamic arrays
In ColdFusion, array indexes are counted starting with position 1, which means that
position 1 is referenced as
firstname[1].
Now you can add to the current firstname array example. For 2D arrays, you
reference an index by specifying two coordinates: myarray[1][1].
Function Description
ArrayAppend Creates a new array index at the end of the array
ArrayPrepend
Creates a new array index at the beginning of the array
ArrayInsertAt
Inserts an array index and data