arraySum

Description

Array sum function.

Categories

Syntax

ArraySum(array)

Attributes

AttributeDescriptionRequiredDefault
arrayName of an array

Returns

The sum of values in an array. If the array parameter value is an empty array, returns zero.

Example

<h3>ArraySum Example</h3> 
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. ---> 
        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>