How to get the sum of values of an array in ColdFusion

ArraySum() - get sum of values in an array

ArraySum.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ArraySum function example: how to get sum of values in an array</title>
</head>

<body>
<h2 style="color:Green">ArraySum Function Example</h2>

<cfset NumberArray = ArrayNew(1)>
<cfset Temp = Arrayprepend(NumberArray,10)>
<cfset Temp = Arrayprepend(NumberArray,20)>
<cfset Temp = Arrayprepend(NumberArray,30)>
<cfset Temp = Arrayprepend(NumberArray,40)>
<cfdump var="#NumberArray#" label="NumberArray">

<br />
<cfoutput><b>NumberArray[Sum]: #ArraySum(NumberArray)#</b></cfoutput>
</body>
</html>





More ColdFusion examples