View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > ArraySort PreviousNext

ArraySort

Sorts array elements numerically or alphanumerically.

True, if sort is successful; False, otherwise.

Array functions, List functions

ArraySort(array, sort_type [, sort_order ])

ColdFusion MX:

Parameter

Description

array

Name of an array

sort_type

  • numeric: sorts numbers
  • text: sorts text alphabetically, taking case into account (also known as case sensitive). All letters of one case precede the first letter of the other case:

 - aabzABZ, if sort_order = "asc" (ascending sort)

 - ZBAzbaa, if sort_order = "desc" (descending sort)

  • textnocase: sorts text alphabetically, without regard to case (also known as case-insensitive). A letter in varying cases precedes the next letter:

 - aAaBbBzzZ, in an ascending sort; preserves original intra-letter order

 - ZzzBbBaAa, in a descending sort; reverses original intra-letter order

sort_order

  • asc - ascending sort order. Default.

 - aabzABZ or aAaBbBzzZ, depending on value of sort_type, for letters

 - from smaller to larger, for numbers

  • desc - descending sort order.

 - ZBAzbaa or ZzzBbBaAa, depending on value of sort_type, for letters

 - from larger to smaller, for numbers

If an array element is 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.

<!--- This example shows ArraySort --->
<cfquery name = "GetEmployeeNames" datasource = "cfsnippets">
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 descending alphabetically ---> <cfset isSuccessful = ArraySort(myArray, "textnocase", "desc")> ...

Contents > CFML Reference > ColdFusion Functions > ArraySort PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


e2ipi said on Dec 10, 2004 at 12:43 PM :
There is no "unique" option when sorting.
This is what I have done to achive it.
Any idea if this can be done in better way?

<cfset ArraySort(errors,"text")>
<cfset last = ArrayLen(errors)>
<cfloop condition="i le last">
<cfif last_text neq errors[i]>
<cfset last_text = errors[i]>
<cfelse>
<cfset ArrayDeleteAt(errors,i)>
<cfset last = ArrayLen(errors)>
</cfif>
<cfset i = i + 1>
</cfloop>
Adam Cameron said on Jan 19, 2005 at 2:03 PM :
It's not explicit in the docs above that the array is sorted INLINE, which is why the function doesn't return an array. It sorts the original array.

This has been tripping people up.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa16.htm