# [PHP] Re: calculating the average of arrays

```you can use this:

if (isset(\$f[\$index][f_d1_weight]) && !empty(\$f[\$index][f_d1_weight]))
{
// process item here
}

"Bart Verbeek" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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...
>
>
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

```