Returns the sum of values in an array.
ArraySum(array)
Parameter |
Description |
---|---|
array |
Name of an array that contains values to add |
<!--- This example shows the use of ArraySum ---> <html> <head> <title>ArraySum Example</title> </head> <basefont face = "Arial, Helvetica" size = 2> <body bgcolor = "#FFFFD5"> <H3>ArraySum Example</H3> <P> This example uses ArraySum to add two numbers together.<BR> </P> <!--------------------------------------------------------------------- After checking whether the form has been submitted, the following code creates an array and assigns the form fields to the first two elements in the array. ----------------------------------------------------------------------> <cfif IsDefined("FORM.submit")> <cfset myNumberArray = ArrayNew(1)> <cfset myNumberArray[1] = number1> <cfset myNumberArray[2] = number2> <cfif Form.Submit is "Add"> <!--- use ArraySum to add the number in the array ---> <P>The sum of the numbers is <cfoutput>#ArraySum(myNumberArray)#.</cfoutput> </cfif> </cfif> <!--------------------------------------------------------------------- The following form provides two numeric fields that are added when the form is submitted. ----------------------------------------------------------------------> <form action = "arraysum.cfm" method = "post"> <input type = "hidden" name = "number1_Float"> <input type = "hidden" name = "number2_Float"> <input type = "text" name = "number1"> <BR> <input type = "text" name = "number2"> <BR> <input type = "submit" name = "submit" value = "Add"> </FORM> </body> </html>