Populating Arrays With Data; Populating An Array With The Arrayset Function; Populating An Array With The Cfloop Tag - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

<cfset myNewArray=myArray>
<cfdump var=#myNewArray#><br>
<br>
Change the values in the new array.<br>
<cfset myNewArray[1].key1="New first array element">
<cfset myNewArray[2]="New second array element">
<br>
Contents of the original array after the changes:<br>
<cfdump var=#myArray#><br>
Contents of the new array after the changes:<br>
<cfdump var=#myNewArray#>
The change to the new array also changes the contents of the structure in the original array.
To make a complete copy of an array that contains complex variables, use the
function.

Populating arrays with data

Array elements can store any values, including queries, structures, and other arrays. You can use a
number of functions to populate an array with data, including
ArrayInsertAt
array.
In particular, you should master the following basic techniques:
Populating an array with the
Populating an array with the
Populating an array from a query
The following sections describe these techniques.

Populating an array with the ArraySet function

You can use the
multidimensional array, with some initial value, such as an empty string or zero. This can be
useful if you need to create an array of a certain size, but do not need to add data to it right away.
One reason to do this is so that you can refer to all the array indexes. If you refer to 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 to 100, with an empty string:
ArraySet (myarray, 1, 100, "")

Populating an array with the cfloop tag

The
tag provides a common and very efficient method for populating an array. The
cfloop
following example uses a
array with the names of the months. A second
<cfset months=arraynew(1)>
<cfloop index="loopcount" from=1 to=12>
<cfset months[loopcount]=MonthAsString(loopcount)>
</cfloop>
110
Chapter 5: Using Arrays and Structures
, and
. These functions are useful for adding data to an existing
ArrayPrepend
ArraySet
cfloop
function to populate a 1D array, or one dimension of a
ArraySet
tag and the
cfloop
function
tag
MonthAsString
outputs data in the array to the browser.
cfloop
Duplicate
,
ArraySet
ArrayAppend
function to populate a simple 1D
,

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Coldfusion mx

Table of Contents