Re: calculating the average of arrays
| From: | _lallous | Date: | Tue, 04 Sep 2001 13:07:06 +0000 |
| Subject: | Re: calculating the average of arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65881@lists.php.net to get a copy of this message | ||
you can use this:
if (isset($f[$index][f_d1_weight]) && !empty($f[$index][f_d1_weight]))
{
// process item here
}
"Bart Verbeek" <b.verbeek@creative-edge.nl> wrote in message
news:KDEGLILLMKMDKJGAMGHIAEOICAAA.b.verbeek@creative-edge.nl...
> 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...
>
>
>
>