About Structures; Structure Notation - MACROMEDIA COLDFUSION 4.5-DEVELOPING WEB Develop Manual

Developing web applications with coldfusion
Table of Contents

Advertisement

Chapter 9: Handling Complex Data with Structures

About Structures

ColdFusion supports the creation and handling of structures, which enable developers
to create and maintain key-value pairs. A structure lets you build a collection of related
variables that are grouped under a single name. Structures can also be used as
associative arrays. You can define ColdFusion structures dynamically.
You can use structures to refer to related string values as a unit rather than individually.
To maintain employee lists, for example, you can create a structure that holds
personnel information such as name, address, phone number, ID number, etc. Then
you can refer to this collection of information as a structure called employee rather
than as a collection of individual variables.

Structure notation

There are three types of notation for structures:
Types of Structure Notation
Notation
Objects.property
Associative arrays
Structure functions
Description
Use to refer to values in a structure. So a property,
prop, of an object, obj, can be referred to as obj.prop.
This notation is useful for simple assignments, as in
this example:
depts.John="Sales"
Use this notation only when the property names
(keys) are known in advance and they are strings,
with no special characters, numbers, or spaces. You
cannot use the dot notation when the property, or
key, is dynamic.
If the key name is not known in advance, or contains
spaces, numbers or special characters, you can use
associative array notation. This uses structures as
arrays with string indexes, for example,
depts["John"] or depts["John Doe"]="Sales."
See
"Using Structures as Associative Arrays" on page
119
for more information.
The structure functions should be used when the
simpler syntax styles described above cannot be
used, for example when dynamic keys are required.
The sections in this chapter describe how to use the
structure functions.
113

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION 4.5-DEVELOPING WEB and is the answer not in the manual?

This manual is also suitable for:

Coldfusion 4.5

Table of Contents