User Guide

ArrayAvg 377
ArrayAvg
Description
Calculates the average of the values in an array.
Returns
Number. If the array parameter value is an empty array, returns zero.
Category
Array functions, Mathematical functions
Function syntax
ArrayAvg(array)
See also
ArraySum
Parameters
Usage
The following example uses the ColdFusion built-in variable Form.fieldNames, which is
available on the action page of a form. It contains a comma-delimited list of the names of the
fields on the form.
Example
<!--- This example shows the use of ArrayAvg --->
<!-- The following lines of code keep track of the form fields that can
be dynamically generated on the screen. It uses the Fieldnames variable
with the ListLen function to determine the number of fields on the form. --->
<cfset FormElem = 2>
<cfif Isdefined("Form.Submit")>
<cfif Form.Submit is "More">
<cfset FormElem = ListLen(Form.Fieldnames)>
</cfif>
</cfif>
<html>
<head>
<title>ArrayAvg Example</title>
</head>
<body>
<h3>ArrayAvg Example</h3>
<p> This example uses ArrayAvg to find the average of the numbers that you
enter
into an array.<br>
To enter more than two numbers press the <b>more</b> button.
</p>
<form action = "arrayavg.cfm">
<!--- The following code initially creates two fields. It adds fields if the
user
presses MORE. FormElem is initialized to two at the beginning of this
code to show that the form has two fields. ----->
<input type = "submit" name = "submit" value = "more">
Parameter Description
array Name of an array