2 Comments

ColdFusion – Array Merge


Let’s say you have 2 arrays and you would like merge the two into one array.

You can do it the long way by looping over the arrays or even better, you can use this simple ColdFusion function I have put together.

<cffunction name=”arrayMerge” access=”public” returntype=”array” output=”false” hint=”Appends array2 to array1 and returns merged array”>
<cfargument name=”array1″ required=”true” type=”array”>
<cfargument name=”array2″ required=”true” type=”array”>

<cfset var a1 = arguments.array1>
<cfset a1.addAll(arguments.array2)>

<cfreturn a1 />
</cffunction>

About these ads

2 comments on “ColdFusion – Array Merge

  1. Sweet.
    Where in the CF reference is array.addAll() documented? I found a Flex reference in the mx.collections that looks like an equivalent to ListAppend.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 31 other followers

%d bloggers like this: