User Guide

Table Of Contents
114 Chapter 5: Using Arrays and Structures
However, if the key is dynamic, or contains special characters, you must use the
StructKeyExists function.
Note: Using StructKeyExists to test for the existence of a structure entry is more efficient than using
IsDefined. ColdFusion scopes are available as structures and you can improve efficiency by using
StructKeyExists to test for the existence of variables.
Getting a list of keys in a structure
To get a list of the keys in a CFML structure, you use the
StructKeyList function, as follows:
<cfset temp=StructKeyList(structure_name, [delimiter] )>
You can specify any character as the delimiter; the default is a comma.
Use the
StructKeyArray function to returns an array of keys in a structure, as follows:
<cfset temp=StructKeyArray(structure_name)>
Note: The
StructKeyList and StructKeyArray functions do not return keys in any particular order.
Use the
ListSort or ArraySort functions to sort the results.
Copying structures
ColdFusion provides several ways to copy structures and create structure references. The
following table lists these methods and describes their uses:
Technique Use
Duplicate
function
Makes a complete copy of the structure. All data is copied from the original
structure to the new structure, including the contents of structures, queries, and
other objects. As a result changes to one copy of the structure have no effect on
the other structure.
This function is useful when you want to move a structure completely into a new
scope. In particular, if a structure is created in a scope that requires locking (for
example, Application), you can duplicate it into a scope that does not require
locking (for example, Request), and then delete it in the scope that requires
locking.
StructCopy
function
Makes a shallow copy of a structure. It creates a new structure and copies all
simple variable and array values at the top level of the original structure to the
new structure. However, it does not make copies of any structures, queries, or
other objects that the original structure contains, or of any data inside these
objects. Instead, it creates a reference in the new structure to the objects in the
original structure. As a result, any change to these objects in one structure also
changes the corresponding objects in the copied structure.
The Duplicate replaces this function for most, if not all, purposes.
Variable
assignment
Creates an additional reference, or alias, to the structure. Any change to the data
using one variable name changes the structure that you access using the other
variable name.
This technique is useful when you want to add a local variable to another scope
or otherwise change a variable’s scope without deleting the variable from the
original scope.