Adobe COLDFUSION 9 Manual page 90

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Creating arrays using functions
To create an array explicitly, you use the
example:
<cfset myNewArray=ArrayNew(2)>
This line creates a two-dimensional array named myNewArray. You use this method to create an array with up to three
dimensions.
After you create an array, you add array elements, which you can then reference by using the element indexes.
For example, suppose you create a one-dimensional array called firstname:
<cfset firstname=ArrayNew(1)>
The array firstname holds no data and is of an unspecified length. Next you add data to the array:
<cfset firstname[1]="Coleman">
<cfset firstname[2]="Charlie">
<cfset firstname[3]="Dexter">
After you add these names to the array, it has a length of 3.
Creating and using arrays implicitly
To create an array implicitly, you do not use the
side of an assignment statement, and array notation on the right side of the statement, as in the following example:
<cfset firstnameImplicit=["Coleman","Charlie","Dexter"]>
This single statement is equivalent to the four statements used to create the
functions" on page 85.
When you create an array implicitly, the right side of the assignment statement has brackets ([]) surrounding the array
contents and commas separating the individual array elements. The elements can be literal values, such as the strings
in the example, variables, or expressions. If you specify variables, do not place the variable names in quotation marks.
You can create an empty array implicitly, as in the following example:
<cfset myArray = []>
You can also create an array implicitly by assigning a single entry, as the following example shows:
<cfset chPar[1] = "Charlie">
<cfset chPar[2] = "Parker">
ColdFusion does not allow nested implicit creation of arrays, structures, or arrays and structures. Therefore, you
cannot create a multidimensional array in a single implicit statement. For example, neither of the following statements
is valid:
<cfset myArray = [[],[]]>
<cfset jazzmen = [["Coleman","Charlie"],["Hawkins", "Parker"]]
To create a two-dimensional array, for example, use a format such as the following:
<cfset ch = ["Coleman", "Hawkins"]>
<cfset cp = ["Charlie", "Parker"]>
<cfset dg = ["Dexter", "Gordon"]>
<cfset players = [ch, cp, dg]>
You cannot use a dynamic variable when you create an array implicitly. For example, the following expression
generates an error:
function and specify the array dimensions, as in the following
arrayNew
function. Instead, you use a new variable name on the left
ArrayNew
Last updated 8/5/2010
array in
"Creating arrays using
firstname
85

Advertisement

Table of Contents
loading

Table of Contents