arrayPrepend

Description

Inserts an array element at the beginning of an array.

Categories

Related

Syntax

ArrayPrepend(array, value)

Attributes

AttributeDescriptionRequiredDefault
arrayName of an array
valueValue to insert at beginning of array

Returns

True, on successful completion.

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> 
    The contents of the array are as follows: 
    #myList# 
</cfoutput>