|
ArrayPrepend
DescriptionInserts
an array element at the beginning of an array.
ReturnsTrue,
on successful completion.
Function syntaxArrayPrepend(array, value)
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>
|