calculating the average of arrays
| From: | Bart Verbeek | Date: | Tue, 04 Sep 2001 11:58:03 +0000 |
| Subject: | calculating the average of arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-65879@lists.php.net to get a copy of this message | ||
Hello,
I want to calculate an average from the following variables/arrays
a - $f[$index][f_d1_perc] with $f[$index][f_d1_weight]
b - $f[$index][f_d2_perc] with $f[$index][f_d2_weight]
c - $f[$index][f_d3_perc] with $f[$index][f_d3_weight]
d - $f[$index][f_d4_perc] with $f[$index][f_d4_weight]
e - $f[$index][f_d5_perc] with $f[$index][f_d5_weight]
All varables are integers:
- $f[$index][f_d _perc] = 0 - 100
- $f[$index][f_d1_weight] = 0 - 10
I want the folowing:
total score = (a * weight) + (b * weight) + (c * weight) + (d * weight)
+ (e * weight).
total vars = weight a + weight b + weight c + weight d + weight e.
Average = total score / total average.
The calulated average has to be stored in "$f[$index][f_perc]".
The problem is that not always all the variables are set. How do I check
these arrays and leave them out of the calculation when they don't contain a
value.
Hope anyone can help me...