– Common Function Library Project

arrayOfStructsToStructsOfStructs(array, key)

Last updated June 11, 2009


Tayo Akinmade

Version: 0 | Requires: CF6 | Library: DataManipulationLib

This UDF accepts an array of structures and converts it to a structure of structures. It accepts an array of structures and a key as mandatory arguments. The key must exist in all structures in the array

Return Values:
Returns a struct.


<cfset aArray = arrayNew(1)>

<cfset stStruct1 = structNew()>
<cfset = "Micheal">
<cfset stStruct1.age = 20>

<cfset stStruct2 = structNew()>
<cfset = "Smidt">
<cfset stStruct2.age = 25>

<cfset aArray[1] = stStruct1>
<cfset aArray[2] = stStruct2>

<cfset stStructOfStructs = ArrayOfStructsToStructsOfStructs(array=aArray,key="name"))>
<cfdump var="#stStructofStructs#">


Name Description Required
array An array of structs. Yes
key A key value to use for the new structure. Must exist in all structs in the array. Yes

Full UDF Source:

 Converts an array of structures to an structure of structures,
 @param array      An array of structs. (Required)
 @param key      A key value to use for the new structure. Must exist in all structs in the array. (Required)
 @return Returns a struct. 
 @author Tayo Akinmade ( 
 @version 0, June 11, 2009 
<cffunction name="ArrayOfStructsToStructsOfStructs" access="public" output="false" returntype="struct" hint="Converts an array of structs to an struct of structs">
        <cfargument name="array" type="array" required="true" hint="An array of structures">
        <cfargument name="key" type="string" required="true" hint="Key to use">
            var stStructOfStructs = structNew();
            var i = 0;
            // loop over array
            for(i=1;i lte arrayLen(arguments.array);i=i+1){
                stStructOfStructs[arguments.array[i][arguments.key]] = arguments.array[i];
            return stStructOfStructs;


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson