ArraySort

Description

Sorts array elements numerically or alphanumerically.


Note

If the sort is successful, ArraySort returns "Yes". If not, ArraySort returns "No".


Category

Array functions

Syntax

ArraySort(array, sort_type [, sort_order ]) 

Parameters

Parameter
Description
array
Name of an array to sort
sort_type
The type of sort to execute:
  • numeric    numerically
  • text    alphabetically, uppercase before lowercase
  • textnocase    alphabetically; case is ignored
sort_order
The sort order to enforce:
  • asc    (Default) Ascending
  • desc    Descending

Example

<!--- This example shows ArraySort --->
<html>
<head>
<title>ArraySort Example</title>
</head>
<body>
<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")>
...