I have an foreach loop that takes some values from a MySQL database. The foreach it's very simple but with about 100 rows, like:
foreach($values as $value){}
what i'm trying to do but i don't know how it's to make inside the foreach the average of the previous 5 rows. So starting from the 5th row to do the average of the rows 1-5 then on the row 6 to do the average of rows 2-6 etc.
later edit, an simple example ex:
$values = array(1,2,3,4,5,6,7,8,9,10);
$i = 0;
foreach($values as $value){
if $i > 5{$average = (1+2+3+4+5)/5 }
// and here continue like if $i = 6 {$average = (2+3+4+5+6)/5}
// if $i = 7 {$average = (3+4+5+6+7)/5}
$i++;
}