arrayToList

Description

Converts a one-dimensional array to a list.

Categories

Syntax

ArrayToList(array[, delimiter])

Attributes

AttributeDescriptionRequiredDefault
arrayName of array
delimiterCharacter or multicharacter string to separate list elements. The default value is comma.

Returns

Delimited list, as a string.

Example

<h3>ArrayToList Example</h3> 
 
<cfquery name = "GetEmployeeNames" datasource = "cfdocexamples"> 
    SELECT FirstName, LastName FROM Employees 
</cfquery> 
 
<!--- Create an array. ---> 
<cfset myArray = ArrayNew(1)> 
 
<!--- Loop through the query, append 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 myAlphaArray = ArraySort(myArray, "textnocase", "desc")> 
 
<!--- Show the resulting alphabetized array as a list. ---> 
<cfset myAlphaList = ArrayToList(myArray, ",")> 
 
<!--- Output the array as a list. ---> 
<cfoutput> 
    The contents of the array are as follows: 
    #myList# 
    This array, alphabetized by first name (descending): 
    #myAlphaList# 
    This array has #ArrayLen(MyArray)# elements. 
</cfoutput>