MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual page 140

Table of Contents

Advertisement

120
<!--- This example adds a 1D array to a 1D array --->
<!--- Declare two one-dimensional arrays for the first and last names
--->
<cfset firstname=arraynew(1)>
<cfset lastname=arraynew(1)>
<!--- Assign first names directly to the firstname array --->
<cfset firstname[1]="Coleman">
<cfset firstname[2]="Charlie">
<cfset firstname[3]="Dexter">
<!--- Declare the full name array --->
<cfset fullname=arraynew(1)>
<!--- Add the firstname array to index 1 and the lastname array to
<cfset fullname[1]=firstname>
<cfset fullname[2]=Lastname>
<!--- Add the last names using reference to the fullname array --->
<cfset fullname[2][1]="Hawkins">
<cfset fullname[2][2]="Parker">
<cfset fullname[2][3]="Gordon">
<cfoutput>
</cfoutput>
Note that because this is a full 2D array, you can easily output names that do not
make sense in the real world.
Additional referencing methods
You can reference array indexes in the standard way: myarray[x] where x is the index
that you want to reference. You can also use ColdFusion expressions inside the
square brackets to reference an index. You can use any of the following ways of
referencing an array index:
<cfset myarray[1]=expression>
<cfset myarray[1 + 1]=expression>
<cfset myarray[arrayindex]=expression>
index 2 of the fullname array --->
#fullname[1][1]# #fullname[2][1]#<br>
#fullname[1][2]# #fullname[2][2]#<br>
#fullname[1][3]# #fullname[2][3]#<br>
#fullname[1][1]# #fullname[2][3]#<br>
Chapter 8 Handling Complex Data with Structures

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents