CFLib.org – Common Function Library Project

ArrayConcat(a1, a2)

Last updated September 13, 2001
Download UDF

author

Craig Fisher                                      Craig Fisher

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

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

Return Values:
Returns an array.

Example:

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

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

Search CFLib.org


Latest Additions

Jose Diaz-Salcedo Jose Diaz-Salcedo added
cfRssFeed
2 day(s) ago

Raymond Compton Raymond Compton added
structBlend
23 day(s) ago

Duncan Duncan added
IsZIPUK
23 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
29 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson