User Guide

Table Of Contents
Creating and using structures 111
Creating and using structures
This section explains how to create and use structures in ColdFusion. The sample code in this
section uses a structure called employee, which is used to add new employees to a corporate
information system.
Creating structures
You can create a structure by creating a first key-pair or by using the ColdFusion
StructNew
function.
Creating structures by assigning values
You can create a structure by assigning a key-value pair. For example, the following line creates a
structure named myStruct with one element, name, that has the value Macromedia.
<cfset myStruct.name="Macromedia">
Note: You can also create a structure using the structname["keyname"] format; for example,
<cfset
myStruct[“name”] ="Macromedia">
.
<cfoutput>
Value of the first key<br>
#mystruct.key1#<br>
#mystruct["key1"]#<br>
#mystruct[key1Var]#<br>
<br>
Output the value of the structure’s key1 (string) entry
using the following notation:
object.property notation
associative array notation with a constant
associative array notation with a variable
Value of the second entry in the
key2 array<br>
#myStruct.key2[2]#<br>
#myStruct["key2"][2]#<br>
#myStruct[key2Var][2]#<br>
#myStruct[key2Var][var2]#<br>
<br>
Output the value of the second entry in the
structure’s key2 array using the following notation:
object.property notation
associative array notation with a constant
associative array notation with a variable
associative array notation with variables for both
the array and the array index
Value of the struct2key2 entry in
the key3 structure<br>
#myStruct.key3.struct2key2#<br>
#myStruct["key3"]["struct2key2"]#<br>
#myStruct[key3Var]["struct2key2"]#<br>
#myStruct.key3["struct2key2"]#<br>
#myStruct["key3"].struct2key2#<br>
<br>
</cfoutput>
Output the value of second entry in the structure’s
key3 embedded structure using the following
notation:
object.property notation
associative array notation with two constants
associative array notation with a variable and a
constant
object.property notation followed by associative
array notation
associative array notation followed by
object.property notation
Code Description