structUpdateVals(struct1, struct2)
Last updated December 22, 2005
Version: 1 | Requires: CF6 | Library: DataManipulationLib
Description:
This function will find the matching keys between two structures and update structure1 values with structure2 values. If structure2 has more keys than structure1 the keys will not be added.
Return Values:
Returns a structure.
Example:
<cfset struct1 = structNew() />
<cfset struct1['FNAME'] = "John" />
<cfset struct1['LNAME'] = "Smith" />
<cfset struct1['PHONE'] = "305.555.5555" />
<cfset struct2 = structNew() />
<cfset struct2['FNAME'] = "Bill" />
<cfset struct2['LNAME'] = "Gates" />
<cfdump var="#struct1#" label="Struct 1">
<cfdump var="#struct2#" label="Struct 2">
<cfset structUpdateVals(struct1, struct2) />
<cfdump var="#struct1#" label="Updated Struct 1">
Parameters:
Name | Description | Required |
---|---|---|
struct1 | The structure to be modified. | Yes |
struct2 | The structure to copy values from. | Yes |
Full UDF Source:
<!---
Update one structure values with values from another structure for those keys that match.
@param struct1 The structure to be modified. (Required)
@param struct2 The structure to copy values from. (Required)
@return Returns a structure.
@author Jorge Loyo (loyoj@fiu.edu)
@version 1, December 22, 2005
--->
<cffunction name="structUpdateVals" returntype="struct" output="false">
<cfargument name="struct1" required="yes" type="struct" />
<cfargument name="struct2" required="yes" type="struct" />
<cfloop collection="#struct2#" item="key">
<cfif structKeyExists(struct1, key)>
<cfset structUpdate(struct1, key, struct2[key]) />
</cfif>
</cfloop>
<cfreturn struct1 />
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016