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
structure can contain keys such as
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 most other variable scopes.
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
Employee, you use the following code:
<cfset Employee = StructNew( )>
Just like arrays, structures can also
be created using the
<cfparam name="Employee" type="Struct" default="#StructNew( )#">
Be sure to wrap the
StructNew( ) function with hash marks to avoid having ColdFusion treat the ...