 <p>You can use <code>array_slice()</code> for slice and <code>array_sum()</code> to calculate total then average. An example here</p> <pre><code>$values = array(1,2,3,4,5,6,7,8,9,10); foreach($values as $k=&gt;$v){ if($k &gt; 4){ echo $ave = array_sum(array_slice($values, $k - 5, $k)) / 5 . '&lt;br /&gt;'; } } </code></pre>