Additional Referencing Methods; Populating Arrays With Data; Populating An Array With Arrayset; Populating An Array With Cfloop - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

108
<CFOUTPUT>
#fullname[1][1]# #fullname[2][1]#<BR>
#fullname[1][2]# #fullname[2][2]#<BR>
#fullname[1][3]# #fullname[2][3]#<BR>
</CFOUTPUT>

Additional referencing methods

You can reference array indexes in the standard way: myarray[x] where x is the index
you want to reference. You can also use ColdFusion expressions inside the square
brackets to reference an index. The following are valid ways of referencing an array
index:
<CFSET myarray[1]= expression >
<CFSET myarray[1 + 1]= expression >
<CFSET myarray[arrayindex]= expression >

Populating Arrays with Data

One-dimensional arrays can store any values, including queries, structures, and other
arrays. You can use a number of functions to populate an array with data, including
ArraySet, ArrayAppend, ArrayInsertAt, and ArrayPrepend. These functions are useful
for adding data to an existing array. In addition, several basic techniques are important
to master:

Populating an array with ArraySet

Populating an array with CFLOOP

Populating an array from a query
Populating an array with ArraySet
You can use the ArraySet function to populate a 1D array, or one dimension of a multi-
dimensional array, with some initial value such as an empty string or 0 (zero). This can
be useful if you need to create an array of a certain size, but don't need to add data to it
right away. Array indexes need to contain some value, such as an empty string, in order
to be referenced.
Use ArraySet to initialize all elements of an array to some value:
ArraySet (arrayname, startrow, endrow, value)
This example initializes the array myarray, indexes 1 to 100, with an empty string.
ArraySet (myarray, 1, 100, "")
Populating an array with CFLOOP
A common and very efficient method for populating an array is by creating a looping
structure that adds data to an array based on some condition using CFLOOP.
Developing Web Applications with ColdFusion

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 4.5

Table of Contents