Array sum function.
The sum of values in an array. If the array parameter value is an empty array, returns zero.
Array functions, Mathematical functions
ArraySum(array
)
Parameter |
Description |
---|---|
array |
Name of an array |
<h3>ArraySum Example</h3> <p>This example uses ArraySum to add two numbers.<br> </p> <!--- After checking whether the form has been submitted, the 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> <!--- This 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>