Inserts an array element at the beginning of an array.
True, on successful completion.
ArrayPrepend(array,value)
ArrayAppend; "Adding elements to an array" in the ColdFusion Developer's Guide
|
Parameter |
Description |
|---|---|
| array |
Name of an array |
| value |
Value to insert at beginning of array |
<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, becuase 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>