Name

StructSort — New as of ColdFusion 4.5.1 SP2

Synopsis

StructSort(base [,sorttype, sortorder, pathtosubelement])

Returns an array of structures with the top-level key names sorted by the subelement specified by pathtosubelement. base is a required parameter and specifies the name of the top-level structure containing the element you want to sort. sorttype is an optional parameter and specifies the type of sort to perform (numeric, text, or textnocase). sortorder is also optional and specifies the sort order for the operation (asc, for ascending (the default), or desc, for descending). pathtosubelement is optional and specifies the path (using dot notation) from the base to the subelement you wish to sort on. Leaving pathtosubelement blank results in the sort being performed on the top-level structure specified in base. Only substructures of structures may be specified in pathtosubelement. Here’s an example that demonstrates the use of this function:

<CFSET Quotes = StructNew( )> <CFSET Stocks = StructNew( )> <!--- populate both structures ---> <CFLOOP INDEX="i" FROM="1" TO="5"> <CFSET Price = NumberFormat((rand( )*100),'99.99')> <CFSET Quotes["Stock#i#"] = Price> <CFSET Stock = StructNew( )> <CFSET Stock.Price = Price> <CFSET Stocks["Stock#i#"] = Stock> </CFLOOP> <CFOUTPUT> <H2>Quote Structure</H2> Sort Stock Name by Price (No parameters): #ArrayToList(StructSort(Quotes))#<BR> Sort Stock Name by Price (Text, Desc): #ArrayToList(StructSort(Quotes, "Text", "Desc"))#<P> Sort Stock ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.