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
CFML Reference / 

StructCopy

Adobe Community Help


Applies to

  • ColdFusion

Contact support

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

Description

Copies a structure. Copies top-level keys, values, and arrays in the structure by value; copies nested structures by reference.

Returns

A copy of a structure, with the same keys and values; if structure does not exist, throws an exception.

Category

Structure functions

Syntax

StructCopy(structure)

See also

Structure functions in the Developing ColdFusion Applications

Parameters

Parameter

Description

structure

Structure to copy

Usage

The following code shows how this function copies a structure that contains a string field, a number field, and a two-dimensional array at the top-level:

<cfset assignedCopy = StructNew()>
<cfset assignedCopy.string = #struct.string#>
<cfset assignedCopy.number = #struct.number#>
<cfset assignedCopy.array = ArrayNew(2)>
<cfset assignedCopy.array[1][1] = #struct.array[1][1]#>
<cfset assignedCopy.array[1][2] = #sruct.array[1][2]#>
</cfoutput>

The following code shows how StructCopy copies a nested structure:

<cfset assignedCopy.nestedStruct = struct.nestedStruct>
</cfoutput>

To copy a structure entirely by value, use Duplicate.The following table shows how variables are assigned:

Variable type

Assigned by

structure.any_simple_valueBooleanBinaryBase64

Value

structure.array

Value

structure.nested_structure

Reference

structure.object

Reference

structure.query

Reference

Example

<!--- This code shows assignment by-value and by-reference. ---> 
// This script creates a structure that StructCopy copies by value. <br> 
<cfscript> 
// Create elements. 
s = StructNew(); 
s.array = ArrayNew(2); 

// Assign simple values to original top-level structure fields. 
s.number = 99; 
s.string = "hello tommy"; 

// Assign values to original top-level array. 
s.array[1][1] = "one one"; 
s.array[1][2] = "one two"; 
</cfscript> 

<!--- Output original structure ---> 
<hr> 
<b>Original Values</b><br> 
<cfoutput> 
// Simple values <br> 
s.number = #s.number#<br> 
s.string = #s.string#<br> 
// Array value <br> 
s.array[1][1] = #s.array[1][1]#<br> 
s.array[1][2] = #s.array[1][2]#<br> 
</cfoutput> 

// Copy this structure to a new structure. <br> 
<cfset copied = StructCopy(s)> 

<cfscript> 
// Change the values of the original structure. <br> 
s.number = 100; 
s.string = "hello tommy (modified)"; 
s.array[1][1] = "one one (modified)"; 
s.array[1][2] = "one two (modified)"; 
</cfscript> 
<hr> 
<b>Modified Original Values</b><br> 
<cfoutput> 
// Simple values <br> 
s.number = #s.number#<br> 
s.string = #s.string#<br> 
// Array value <br> 
s.array[1][1] = #s.array[1][1]#<br> 
s.array[1][2] = #s.array[1][2]#<br> 
</cfoutput> 
<hr> 
<b>Copied structure values should be the same as the original.</b><br> 
<cfoutput> 
// Simple values <br> 
copied.number = #copied.number#<br> 
copied.string = #copied.string#<br> 
// Array value <br> 
copied.array[1][1] = #copied.array[1][1]#<br> 
copied.array[1][2] = #copied.array[1][2]#<br> 
</cfoutput> 

// This script creates a structure that StructCopy copies by reference. 
<cfscript> 
// Create elements. 
s = StructNew(); 
s.nested = StructNew(); 
s.nested.array = ArrayNew(2); 
// Assign simple values to nested structure fields. 
s.nested.number = 99; 
s.nested.string = "hello tommy"; 
// Assign values to nested array. 
s.nested.array[1][1] = "one one"; 
s.nested.array[1][2] = "one two"; 
</cfscript> 

<!--- Output original structure ---> 
<hr> 
<b>Original Values</b><br> 
<cfoutput> 
// Simple values <br> 
s.nested.number = #s.nested.number#<br> 
s.nested.string = #s.nested.string#<br> 

// Array values <br> 
s.nested.array[1][1] = #s.nested.array[1][1]#<br> 
s.nested.array[1][2] = #s.nested.array[1][2]#<br> 
</cfoutput> 

// Use StructCopy to copy this structure to a new structure. <br> 
<cfset copied = StructCopy(s)> 
// Use Duplicate to clone this structure to a new structure. <br> 
<cfset duplicated = Duplicate(s)> 

<cfscript> 
// Change the values of the original structure. 
s.nested.number = 100; 
s.nested.string = "hello tommy (modified)"; 
s.nested.array[1][1] = "one one (modified)"; 
s.nested.array[1][2] = "one two (modified)"; 
</cfscript> 
<hr> 
<b>Modified Original Values</b><br> 
<cfoutput> 
// Simple values <br> 
s.nested.number = #s.nested.number#<br> 
s.nested.string = #s.nested.string#<br> 

// Array value <br> 
s.nested.array[1][1] = #s.nested.array[1][1]#<br> 
s.nested.array[1][2] = #s.nested.array[1][2]#<br> 
</cfoutput> 

<hr> 
<b>Copied structure values should reflect changes to original.</b><br> 
<cfoutput> 
// Simple values <br> 
copied.nested.number = #copied.nested.number#<br> 
copied.nested.string = #copied.nested.string#<br> 
// Array values <br> 
copied.nested.array[1][1] = #copied.nested.array[1][1]#<br> 
copied.nested.array[1][2] = #copied.nested.array[1][2]#<br> 
</cfoutput> 

<hr> 
<b>Duplicated structure values should remain unchanged.</b><br> 
<cfoutput> 
// Simple values <br> 
duplicated.nested.number = #duplicated.nested.number#<br> 
duplicated.nested.string = #duplicated.nested.string#<br> 
// Array value <br> 
duplicated.nested.array[1][1] = #duplicated.nested.array[1][1]#<br> 
duplicated.nested.array[1][2] = #duplicated.nested.array[1][2]#<br> 
</cfoutput>

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