O'Reilly logo

Programming ColdFusion MX, 2nd Edition by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Arrays

An array is an object that stores indexed values. Each value stored in an array is referred to as an element of the array. Each element has an integer assigned to it that marks its position within the array. This number is referred to as the element’s index. Arrays elements can store any ColdFusion datatype including additional arrays.

As previously discussed, ColdFusion supports one-dimensional (think of this as a single column of data or a list), two-dimensional (think of this as a spreadsheet with rows and columns), and three-dimensional (think of this as a cube of data) arrays. Additional dimensions can be created dynamically by nesting multidimensional arrays (creating an array of arrays). ColdFusion arrays differ slightly from traditional arrays found in other programming languages. Whereas traditional arrays are fixed in size, ColdFusion arrays are dynamic. This means that a ColdFusion array can expand or contract as elements are added and removed from the array.

Arrays can store groups of related data such as the contents of a visitor’s shopping cart, student test scores, or historic stock prices. Because array elements can store any ColdFusion datatype, they are ideal for storing complex objects such as an array of query result sets or an array of structures.

Initializing an Array

Initializing an array in ColdFusion is accomplished using the ArrayNew( ) function. This function takes a single argument that determines the number of dimensions for the array (1, 2, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required