108
Developing Web Applications with ColdFusion
<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.
Содержание COLDFUSION 4.5-DEVELOPING WEB
Страница 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Страница 14: ...xiv Developing Web Applications with ColdFusion...
Страница 26: ...xxvi Developing Web Applications with ColdFusion...
Страница 34: ...8 Developing Web Applications with ColdFusion...
Страница 70: ...44 Developing Web Applications with ColdFusion...
Страница 84: ...58 Developing Web Applications with ColdFusion...
Страница 114: ...88 Developing Web Applications with ColdFusion...
Страница 148: ...122 Developing Web Applications with ColdFusion...
Страница 174: ...148 Developing Web Applications with ColdFusion...
Страница 208: ...182 Developing Web Applications with ColdFusion...
Страница 244: ...218 Developing Web Applications with ColdFusion...
Страница 274: ...248 Developing Web Applications with ColdFusion...
Страница 288: ...262 Developing Web Applications with ColdFusion...
Страница 300: ...274 Developing Web Applications with ColdFusion...
Страница 350: ...324 Developing Web Applications with ColdFusion...
Страница 362: ...336 Developing Web Applications with ColdFusion...