| CFML Reference
|
|
ColdFusion Functions
|
ArrayPrepend
Description
Adds an array element to the beginning of an array. Returns a Boolean TRUE on successful completion.
Category
Array functions
Syntax
ArrayPrepend(array, value)
See also
ArrayAppend
Parameters
| Parameter |
Description |
array
|
Name of an array to which to prepend data.
|
value
|
The value to add to the beginning of the array.
|
Example <!--- This example shows ArrayPrepend --->
<html>
<head>
<title>ArrayPrepend Example</title>
</head>
<body>
<H3>ArrayPrepend Example</H3>
<cfquery name = "GetEmployeeNames" datasource = "cfsnippets">
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 the query. Append these names successively
before the last element (this 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>
</body>
</html>
|
Copyright © 2001, Macromedia Inc. All rights reserved. |
|
|