User Guide

Table Of Contents
52 Chapter 3: Using ColdFusion Variables
Complex data types
Arrays, structures, and queries are ColdFusion built-in complex data types. Structures and queries
are sometimes referred to as objects, because they are containers for data, not individual data
values.
For details on using arrays and structures, see Chapter 5, “Using Arrays and Structures,” on
page 97.
Arrays
Arrays are a way of storing multiple values in a table-like format that can have one or more
dimensions. To create an array and specify its initial dimensions, use the ColdFusion
ArrayNew
function. For example, the following line creates an empty two-dimensional array:
<cfset myarray=ArrayNew(2)>
You reference elements using numeric indexes, with one index for each dimension. For example,
the following line sets one element of a two-dimensional array to the current date and time:
<cfset myarray[1][2]=Now()>
The ArrayNew function can create arrays with up to three dimensions. However, there is no limit
on array size or maximum dimension. To create arrays with more than three dimensions, create
arrays of arrays.
After you create an array, you can use functions or direct references to manipulate its contents.
When you assign an existing array to a new variable, ColdFusion creates a new array and copies
the old arrays contents to the new array. The following example creates a copy of the original
array:
<cfset newArray=myArray>
For more information on using arrays, see Chapter 5, “Using Arrays and Structures,” on page 97.
Structures
ColdFusion structures consist of key-value pairs, where the keys are text strings and the values can
be any ColdFusion data type, including other structures. Structures let you build a collection of
related variables that are grouped under a single name. To create a structure, use the ColdFusion
StructNew function. For example, the following line creates a new, empty, structure called depts:
<cfset depts=StructNew()>
ToBinary
Converts Base64 encoded data to binary data. Macromedia recommends using
the
BinaryDecode function, instead of this function, in new applications.
ToString
Converts most simple data types to string data. It can convert numbers, date-time
objects, and boolean values. (It converts date-time objects to ODBC timestamp
strings.) Macromedia recommends that you use the CharsetEncode function to
convert binary data to a string in new applications.
Function Description