Adobe COLDFUSION 9 Manual page 95

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
• Populating an array with the
• Populating an array from a query
Populating an array with the ArraySet function
You can use the
function to populate a 1D array, or one dimension of a multidimensional array, with some
ArraySet
initial value, such as an empty string or zero. This can be useful to create an array of a certain size, without adding data
to it right away. One reason to do this is so that you can reference all the array indexes. If you reference an array index
that does not contain some value, such as an empty string, you get an error.
The
function has the following form:
ArraySet
ArraySet (arrayname, startrow, endrow, value)
The following example initializes the array myarray, indexes 1 - 100, with an empty string:
ArraySet (myarray, 1, 100, "")
Populating an array with the cfloop tag
The
tag provides a common and efficient method for populating an array. The following example uses a
cfloop
tag and the
cfloop
MonthAsString
outputs data in the array to the browser.
cfloop
<cfset months=arraynew(1)>
<cfloop index="loopcount" from=1 to=12>
<cfset months[loopcount]=MonthAsString(loopcount)>
</cfloop>
<cfloop index="loopcount" from=1 to=12>
<cfoutput>
#months[loopcount]#<br>
</cfoutput>
</cfloop>
Using nested loops for 2D and 3D arrays
To output values from 2D and 3D arrays, employ nested loops to return array data. With a one-dimensional (1D)
array, a single
is sufficient to output data, as in the previous example. With arrays of dimension greater than
cfloop
one, you maintain separate loop counters for each array level.
Nesting cfloop tags for a 2D array
The following example shows how to handle nested
tags to populate the array:
cfloop
tag
cfloop
function to populate a simple 1D array with the names of the months. A second
tags to output data from a 2D array. It also uses nested
cfloop
Last updated 8/5/2010
90

Advertisement

Table of Contents
loading

Table of Contents