View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > ArrayAppend PreviousNext

ArrayAppend

Appends an array element to an array.

True, on successful completion.

Array functions

ArrayAppend(array, value)

ArrayPrepend

ColdFusion MX: Changed behavior: this function can be used on XML objects.

Parameter

Description

array

Name of an array

value

Value to add at end of array

<h3>ArrayAppend 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 to the last 
element ---> <cfloop query = "GetEmployeeNames"> <cfoutput>#ArrayAppend(myArray, "#FirstName# #LastName#")# </cfoutput>, Array was appended<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>

Contents > CFML Reference > ColdFusion Functions > ArrayAppend PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


No screen name said on Oct 7, 2004 at 11:52 AM :
is it not possible to append something to an array with out printing YES on the page?
extdw_doc said on Oct 8, 2004 at 10:44 AM :
YES prints in the example because it executes ArrayAppend() inside
of cfoutput tags to show that items are being appended.
YES is the return value for the function so it is output. To get rid
of the YES, remove the <cfoutput></cfoutput> tags surrounding ArrayAppend().
Der Nickname said on Nov 24, 2004 at 5:35 AM :
This looks very good.
But what about 2 or 3 dimentional arrays, how can arrayappend handle them?
Ali210 said on Apr 29, 2005 at 6:15 PM :
I've found that you can also use <cfset> to do an ArrayAppend. it doesnt show the 'Yes' confirmation.

for example -

<cfset ArrayAppend(myarray, firstname)>

NB - firstname can be a variable (as in #firstname# or if you passed it from a form on the previous page, form.firstname. Ofcourse, you could also just specify your value - eg. "David" (make sure you include " speech marks)
Chris Peters said on Nov 28, 2005 at 6:05 AM :
It's also worth noting that passing CFC instances to ArrayAppend() passes them by reference. If you add a CFC instance to an array using this function and then change the instance's state outside of the array, the values within the array reflect those changes as well.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functia3.htm