CFLib.org – Common Function Library Project

structUpdateVals(struct1, struct2)

Last updated December 22, 2005

author

Jorge Loyo

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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson