[thelist] ColdFusion - 2 dimensional array sort

Joshua OIson joshua at alphashop.net
Sat May 26 17:43:53 CDT 2001


You could handcode a sorting algorithm and apply it to your arrays:

http://al.ei.tuat.ac.jp/~sekisita/algoanim-e.html

http://www.scism.sbu.ac.uk/law/Section5/chap2/s5c2p13.html

http://www.cs.princeton.edu/~ah/alg_anim/gawain-4.0/BubbleSort.html

Other people have implemented this using a struct instead of an array and
apply the structsort method.  Here's a siplet from the help file:

StructSort(Base [, PathToSubElement, SortOrder, SortType])

StructSort was added in ColdFusion 4.5.1, SP2. StructSort returns an array
of structures containing top-level key names (strings) sorted according to
the value of the specified sub-element. The value of the keys may be simple
values or complex elements.

Base
A ColdFusion struct with one field (an associative array).

PathToSubElement
Specifies the path to apply to each of the top-level keys in order to reach
the element whose value you wish to sort by. If unspecified,
PathToSubElement, defaults to nothing: meaning that the top-level entries
will be sorted based on their own values.

SortOrder
SortOrder may be "ASC" (ascending) or "DESC" (descending). The default is
"ASC."

SortType
SortType may be "NUMERIC", "TEXT", or "TEXTNOCASE". The default is "TEXT."

The PathToSubElement string does not support array notation so only
substructures of structures are supported.


Good luck,
-joshua

----- Original Message -----
From: "jon steele" <jjsteele22 at yahoo.com>

: Now I want to sort the array using the first element in the second
: "dimension" (if that's what you call it)... that is, using the numeric
: value. So the output when looping throught is this:






More information about the thelist mailing list