User Guide

StructCopy 693
StructCopy
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
Function syntax
StructCopy(structure)
See also
Structure functions
Parameters
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:
<cfoutput>
<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:
<cfoutput>
<cfset assignedCopy.nestedStruct = struct.nestedStruct>
</cfoutput>
To copy a structure entirely by value, use Duplicate on page 466.
The following table shows how variables are assigned:
Parameter Description
structure Structure to copy
Variable type Assigned by
structure.any_simple_value
Boolean
Binary
Base64
Value
structure.array Value
structure.nested_structure Reference