How to sort array elements in ColdFusion

ArraySort() - sort array elements

ArraySort.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ArraySort function example: how to sort array elements</title>
</head>

<body>
<h2 style="color:Green">ArraySort Function Example</h2>

<cfset ColorArray = ArrayNew(1)>
<cfset Temp=ArrayAppend(ColorArray,"Red")>
<cfset Temp=ArrayAppend(ColorArray,"Blue")>
<cfset Temp=ArrayAppend(ColorArray,"Green")>
<cfdump var="#ColorArray#" label="ColorArray">

<br />
<cfset Temp=ArraySort(ColorArray,"text","asc")>
<cfdump var="#ColorArray#" label="ColorArray[Sorted ascending]">

<br />
<cfset Temp=ArraySort(ColorArray,"text","desc")>
<cfdump var="#ColorArray#" label="ColorArray[Sorted descending]">

</body>
</html>





More ColdFusion examples