Unlike the C language, in ColdFusion, array indexes are counted starting with position 1. In C, array indexes start with zero, so position 1 would be referenced as firstname[0]. In ColdFusion, position one is referenced as firstname[1].
Let's add to the current firstname array example. For 2D arrays, you reference an index by specifying two coordinates: myarray[1][1].
<!--- This example adds a 1D array to a 1D array --->
<CFSET firstname=ArrayNew(1)>
<CFSET firstname[1]="Coleman">
<CFSET firstname[2]="Charlie">
<CFSET firstname[3]="Dexter">
<!--- First, declare the array --->
<CFSET fullname=ArrayNew(1)>
<!--- Then, add the firstname array to
index 1 of the fullname array --->
<CFSET fullname[1]=firstname>
<!--- Now we'll add the last names for symmetry --->
<CFSET fullname[2][1]="Hawkins">
<CFSET fullname[2][2]="Parker">
<CFSET fullname[2][3]="Gordon">
<CFOUTPUT>
#fullname[1][1]# #fullname[2][1]#<BR>
#fullname[1][2]# #fullname[2][2]#<BR>
#fullname[1][3]# #fullname[2][3]#<BR>
</CFOUTPUT>
|