Hello,
How do i get to only add the 0+2+3 = 5 / 2 = 2.5
Example:
$date1 = 0
$date2 = 0
$date3 = 0
$date4 =11
$date5 =22
$date6 =33
$date7 =44
$date8 =5
$date9 =55
$date10 =1
$date11 =0
0+0+0+11+22+33+44+5+55+1+0 =171 / 7 24.42
|$date1 | $date2 | $date3 | $date4 | $date5 | $date6 | $date7 | $date8 | $date10 | $date11 |
Call me dumb but how do i use your example to code please!!!!
Thank you,
why only 10? If you have a list of numbers and you add them together then divide by the total #'s, you get a different answer if you take out the one's that are 0.
1+2+3 = 6 / 3 = 2
0+2+3 = 5 / 3 = 1.667
0+2+3 = 5 / 2 = 2.5
are these #'s in an array?
use a foreach loop to calculate the total #'s and the Sum.
to do it without using the 0's:
PHP:--------------------------------------------------------------------------------
$sum = 0;
$num = 0;
foreach($numbers as $value){
if($value > 0){
$sum = $sum + $value;
$num++;
}
}//end foreach
$avg = $sum / $num;
to do it with the 0's, just take out the if statement.