CFLib.org – Common Function Library Project

ArrayConcat(a1, a2)

Last updated September 13, 2001

Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib

 
Rated 2 time(s). Average Rating: 3.0

Description:
Take two arguments, Array1 and Array2. Concatenates Array2 to the end of Array1.

Return Values:
Returns an array.

Example:

view plain print about
<CFSCRIPT>
a1=ArrayNew(1);
a1[1]=1;
a1[2]=2;
a1[3]=3;
a1[4]=4;
a1[5]=5;
a1[6]=6;
a2=ArrayNew(1);
a2[1]="a";
a2[2]=structNew();
a2[2].cheese="fgfgfg";
a2[3]="c";
a2[4]="d";
a3=ArrayConcat(a1, a2);
</cfscript>
a1:
<CFDUMP var="#a1#">
a2:
<CFDUMP var="#a2#">
a3:
<CFDUMP var="#a3#">

Parameters:

Name Description Required
a1 The first array. Yes
a2 The second array. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Concatenates two arrays.
 * 
 * @param a1      The first array. 
 * @param a2      The second array. 
 * @return Returns an array. 
 * @author Craig Fisher (craig@altainetractive.com) 
 * @version 1, September 13, 2001 
 */

function ArrayConcat(a1, a2){
    var i=1;
    if ((NOT IsArray(a1)) OR (NOT IsArray(a2))) {
        writeoutput("Error in <Code>ArrayConcat()</code>! Correct usage: ArrayConcat(<I>Array1</I>, <I>Array2</I>) -- Concatenates Array2 to the end of Array1");
        return 0;
    }
    for (i=1;i LTE ArrayLen(a2);i=i+1) {
        ArrayAppend(a1, Duplicate(a2[i]));
    }
    return a1;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Adam Cameron Adam Cameron added
composeDateTime
21 day(s) ago

Chris Weller Chris Weller added
convertQueryStri...
a while ago

Greg Nettles Greg Nettles added
arrayDiff
a while ago

Nathan Dintenfass Nathan Dintenfass added
ArrayOfStructsSo...
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 36 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Rachel Lehman deAccent
Rated 5.0, 6 time(s)

Isaac Dealey                                      countArbitraryDa...
Rated 5.0, 5 time(s)

Created by Raymond Camden / Design by Justin Johnson