PDA

View Full Version : Average values?


dmeyer
03-23-2006, 04:35 PM
Hey all, been awhile for me and scripting...have a simple question. How do I:

Iterate through an array and average the values in it. However, for each array entry, I want the loop to check against a global
variable to determine whether or not it is considered in the averaging. Thus each array entry will actually have a checkbox
where the user can select whether said entry is condsidered in the averaging.

Morganism
03-23-2006, 07:51 PM
howabout something like:

float $total = 0;
float $count = 0;
for ($each in $all){
if($isIncluded){
$total = $total+$each;
$count+=1;
}
}
float $average = $total/$count;

CGTalk Moderation
03-23-2006, 07:51 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.