User Guide

Table Of Contents
97
CHAPTER 5
Using Arrays and Structures
Macromedia ColdFusion supports dynamic multidimensional arrays. This chapter explains the
basics of creating and handling arrays. It also provides several examples showing how arrays can
enhance your ColdFusion application code.
ColdFusion also supports structures for managing lists of key-value pairs. Because structures can
contain other structures or complex data types as it values, they provide a flexible and powerful
tool for managing complex data. This chapter explains the basics of creating and working with
structures.
Contents
About arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Basic array techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Populating arrays with data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Array functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
About structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Creating and using structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Structure examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Structure functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
About arrays
Traditionally, an array is a tabular structure used to hold data, much like a spreadsheet table with
clearly defined limits and dimensions.
In ColdFusion, you typically use arrays to temporarily store data. For example, if your site lets
users order goods online, you can store their shopping cart contents in an array. This lets you
make changes easily without committing the information, which the user can change before
completing the transaction, to a database.