User Guide

480 Chapter 3: ColdFusion Functions
ArrayPrepend
Description
Inserts an array element at the beginning of an array.
Returns
True, on successful completion.
Category
Array functions
Function syntax
ArrayPrepend(array, value)
See also
ArrayAppend
; “Adding elements to an array” in Chapter 5, “Using Arrays and Structures,” in
ColdFusion MX Developer’s Guide
Parameters
Example
<h3>ArrayPrepend Example</h3>
<cfquery name = "GetEmployeeNames" datasource = "cfdocexamples">
SELECT FirstName, LastName FROM Employees
</cfquery>
<!--- create an array --->
<cfset myArray = ArrayNew(1)>
<!--- set element one to show where we are --->
<cfset myArray[1] = "Test Value">
<!--- loop through query. Append names successively before last element (list
reverses itself from the standard queried output, as it keeps
prepending the array entry) --->
<cfloop query = "GetEmployeeNames">
<cfoutput>#ArrayPrepend(myArray, "#FirstName# #LastName#")#
</cfoutput>, Array was prepended<br>
</cfloop>
<!--- show the resulting array as a list --->
<cfset myList = ArrayToList(myArray, ",")>
<!--- output the array as a list --->
<cfoutput>
<p>The contents of the array are as follows:
<p>#myList#
</cfoutput>
Parameter Description
array Name of an array
value Value to insert at beginning of array