• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

6.3. Structures

A structure is a ColdFusion datatype that allows you to store and manipulate key/value pairs. Structures are similar to one-dimensional arrays, except each element is referenced via an alphanumeric "key" (string) as opposed to a numeric index within the array. Structures are also commonly known as associative arrays or hashes. Structures offer an advantage over arrays in certain situations, by allowing you to reference groups of related information by key as opposed to by numeric index. Structures are useful for storing sets of related data in a single variable. For example, you can easily store an employee's contact information in a structure called Employee. That structure can contain keys such as Name, Address, City, State, and Zip. Additionally, a number of ColdFusion variable scopes are accessible as structures. For example, you can access all form variables available to a page by referencing a structure named Form. A similar structure is also available for several other variable scopes.

6.3.1. Creating a Structure

Structures are created using the StructNew( ) function. Unlike with arrays, you don't have to pass any information to this function. To create a new structure called Stock, you use the following code:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint