Skip to Main Content
Programming ColdFusion MX, 2nd Edition
book

Programming ColdFusion MX, 2nd Edition

by Rob Brooks-Bilson
August 2003
Intermediate to advanced content levelIntermediate to advanced
1140 pages
68h 45m
English
O'Reilly Media, Inc.
Content preview from Programming ColdFusion MX, 2nd Edition

Name

StructSort

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 Name by Price(Numeric, asc): #ArrayToList(StructSort(Quotes, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming ColdFusion

Programming ColdFusion

Rob Brooks-Bilson

Publisher Resources

ISBN: 0596003803Supplemental ContentErrata Page