ArrayToList

Description

Converts a one dimensional array to a list, delimited with the character you specify.

Category

Array functions

Syntax

ArrayToList(array [, delimiter ]) 

Parameters

Parameter
Description
array
Name of an array that contains elements to use to build a list.
delimiter
Specify the character(s) to use to delimit elements in the list. Default is comma ( , ).

Example

<!--- This example shows ArrayToList --->
<html>
<head>
<title>ArrayToList 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 myAlphaArray = ArraySort(myArray, "textnocase", "desc")>
<!--- show the resulting alphabetized array as a list --->
<cfset myAlphaList = ArrayToList(myArray, ",")>
<!--- output the array as a list --->
<cfoutput>
  <P>The contents of the array are as follows:
  <P>#myList#
  <P>This array, alphabetized by first name (descending):
  <P>#myAlphaList#
  <P>This array has #ArrayLen(MyArray)# elements.
</cfoutput>
</body>
</html>