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 are also known 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  
 
 

Developers can use three types of notation for structures:

 
 
  Objects.property  
 

You can use the object.property notation 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.

 
 
  Associative arrays  
 

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 for more information.

 
 
  Structure functions  
 

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.



 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.