For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Developing Applications Help / 

About structures

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

ColdFusion structures consist of key-value pairs. Structures let you build a collection of related variables that are grouped under a single name. You can define ColdFusion structures dynamically.
You can use structures to reference related 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 numbers, and so on. Then you can reference this collection of information as a structure called employee rather than as a collection of individual variables.
A structure key must be a string. The values associated with the key can be any valid ColdFusion value or object. It can be a string or integer, or a complex object such as an array or another structure. Because structures can contain any types of data, they provide a powerful and flexible mechanism for representing complex data.

Structure notation

ColdFusion supports three types of notation for referencing structure contents. The notation that you use depends on your requirements.

Notation

Description

Object.property

You can reference a property, prop, of an object, obj, as obj.prop. This notation, also called dot notation, is useful for simple assignments, as in this example:depts.John="Sales"
Use this notation only when you know the property names (keys) 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 you do not know the key name in advance, or it contains spaces, numbers, or special characters, you can use associative array notation. This notation uses structures as arrays with string indexes; for example:
depts["John"]="Sales"
depts[employeeName] = "Sales"
You can use a variable (such as employeeName) as an associative array index. Therefore, enclose any literal key names in quotation marks. For information on using associative array references containing variables, see Dynamically constructing structure references in Dynamic expressions and dynamic variables.

Structure

Use structure notation only when you create structures and set their initial values, not when you are accessing or updating structure data, and only on the right side of an assignment expression. This notation has the following format:
{keyName=value[,keyName=value]...}
where the square braces ([]) and ellipses (\...) indicate optional contents that can be repeated.The following example creates a structure that uses structure notation:
<cfset name={firstName = "John", lastName = "Smythe"}>

Ordered structs

When you iterate over a struct in ColdFusion, the order of the keys is random. In ColdFusion (2016 release), you can maintain the order of the keys in which you insert them. This insertion order is possible through Ordered structs.

Syntax

myStruct=StructNew("Ordered");

myStruct.first="I am number one.";

myStruct["second"]="I am number two";

You can also create an Ordered struct using literal syntax, as shown below:

myStruct=[first:"I am number one",second="I am number two"];

Example of using ordered structs

<cfscript>
       Beatles=StructNew("Ordered"); // ColdFusion (2016 release) supports ordered structs
       // Set the values of this struct
       Beatles.John="Vocals";
       Beatles.Paul="Guitar and vocals";
       Beatles.George="Lead guitar";
       Beatles.Ringo="Drums";
       // Loop through the struct and display struct values in the order
       // of insertion
       for (i in Beatles)
       {
             WriteOutput("#i#:#Beatles[i]#" & " ");
       }
</cfscript>

Output

JOHN:Vocals PAUL:Guitar and vocals GEORGE:Lead guitar RINGO:Drums

Referencing complex structures

When a structure contains another structure, you reference the data in the nested structure by extending either object.property or associative array notation. You can even use a mixture of both notations.

For example, if structure1 has a key key1 whose value is a structure that has keys struct2key1, struct2key2, and so on, you can use any of the following references to access the data in the first key of the embedded structure:

Structure1.key1.Struct2key1 
Structure1["key1"].Struct2key1 
Structure1.key1["Struct2key1"] 
Structure1["key1"]["Struct2key1"]

The following example shows various ways you can reference the contents of a complex structure:

<cfset myArray=ArrayNew(1)> 
<cfset myArray[1]="2"> 
<cfset myArray[2]="3"> 
<cfset myStruct2=StructNew()> 
<cfset myStruct2.struct2key1="4"> 
<cfset myStruct2.struct2key2="5"> 
<cfset myStruct=StructNew()> 
<cfset myStruct.key1="1"> 
<cfset myStruct.key2=myArray> 
<cfset myStruct.key3=myStruct2> 
<cfdump var=#myStruct#><br> 

<cfset key1Var="key1"> 
<cfset key2Var="key2"> 
<cfset key3Var="key3"> 
<cfset var2="2"> 

<cfoutput> 
Value of the first key<br> 
#mystruct.key1#<br> 
#mystruct["key1"]#<br> 
#mystruct[key1Var]#<br> 
<br> 
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> 
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>

Reviewing the code

The following table describes the code:

Code

Description

 

<cfset myArray=ArrayNew(1)> 
<cfset myArray[1]="2"> 
<cfset myArray[2]="3"> 
<cfset myStruct2=StructNew()> 
<cfset myStruct2.struct2key1="4"> 
<cfset myStruct2.struct2key2="5"> 
<cfset myStruct=StructNew()> 
<cfset myStruct.key1="1"> 
<cfset myStruct.key2=myArray> 
<cfset myStruct.key3=myStruct2>

 

Create a structure with three entries: a string, an array, and an embedded structure.

 

<cfdump var=#myStruct#><br>

 

Display the complete structure.

 

<cfset key1Var="key1"> 
<cfset key2Var="key2"> 
<cfset key3Var="key3">

 

Create variables containing the names of the myStruct keys and the number 2.

 

<cfoutput> 
Value of the first key<br> 
#mystruct.key1#<br> 
#mystruct["key1"]#<br> 
#mystruct[key1Var]#<br> 
<br>

 

Output the value of the key1 (string) entry using the following notation:

  • object.property notation
  • associative array notation with a constant
  • associative array notation with a variable

 

<br> 
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 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>

 

Output the value of second entry in the 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

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices