– Common Function Library Project

structUpdateVals(struct1, struct2)

Last updated December 22, 2005


Jorge Loyo

Version: 1 | Requires: CF6 | Library: DataManipulationLib

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.


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


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 ( 
 @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]) />
	<cfreturn struct1 />
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson