ArrayPrepend

Description

Inserts an array element at the beginning of an array.

Returns

True, on successful completion.

Function syntax

ArrayPrepend(array, value)

See also

ArrayAppend; Adding elements to an array in the Developing ColdFusion Applications

Parameters

Parameter

Description

array

Name of an array

value

Value to insert at beginning of array

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. 
    (The list reverses itself from the standard queried output, because 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>