|
ArraySort
DescriptionSorts
array elements numerically or alphanumerically.
ReturnsTrue,
if sort is successful; False, otherwise.
Function syntaxArraySort(array, sort_type[, sort_order])
HistoryColdFusion
MX:
Changed thrown exceptions: This function can
throw the ArraySortSimpleValueException error and ValueNotNumeric
error.
Changed the order in which sorted elements are returned:
In a textnocase, descending sort, this function
might return elements in a different sort order than in earlier
releases. If sort_type = "textnocase" and sort_order = "desc",
ColdFusion processes elements that differ only in case differently
from earlier releases, as follows:
For
example, in a textnocase, desc sort
of d,a,a,b,A, the following occurs:
ColdFusion MX and later returns d,b,A,a,a
Releases earlier than ColdFusion MX return d,b,a,a,A
Parameters
Parameter
|
Description
|
array
|
Name of an array
|
sort_type
|
- aabzABZ,
if sort_order = "asc" (ascending sort)
-
ZBAzbaa, if sort_order = "desc" (descending sort)
- aAaBbBzzZ, in an
ascending sort; preserves original intra-letter order
- ZzzBbBaAa,
in a descending sort; reverses original intra-letter order
|
sort_order
|
-
aabzABZ or aAaBbBzzZ, depending on value of sort_type,
for letters
- from smaller to larger, for numbers
- ZBAzbaa
or ZzzBbBaAa, depending on value of sort_type,
for letters
- from larger to smaller, for numbers
|
ThrowsIf
an array element is something other than a simple element, this
function throws an ArraySortSimpleValueException error. If sort_type is
numeric and an array element is not numeric, this function throws
a ValueNotNumeric error.
Example<!--- This example shows ArraySort. --->
<cfquery name = "GetEmployeeNames" datasource = "cfdocexamples">
SELECT FirstName, LastName FROM Employees
</cfquery>
<!--- Create an array. --->
<cfset myArray = ArrayNew(1)>
<!--- Loop through the query and append these names successively to the last element. --->
<cfloop query = "GetEmployeeNames">
<cfset temp = ArrayAppend(myArray, "#FirstName# #LastName#")>
</cfloop>
<!--- Show the resulting array as a list. --->
<cfset myList = ArrayToList(myArray, ",")>
<!--- Sort that array in descending order alphabetically. --->
<cfset isSuccessful = ArraySort(myArray, "textnocase", "desc")>
...
|