3v4l.org

run code in 300+ PHP versions simultaneously
<?php $profits = array(5,7,2,4,7,3,6); for($i = 0, $length = count($profits); $i < $length; $i++) { $sixMonthAvg = array_slice($profits, ($i - 5 >= 0 ?$i - 5:0), $i); echo round(array_sum($sixMonthAvg) / count($sixMonthAvg), 2) . PHP_EOL; }

preferences:
52.85 ms | 402 KiB | 5 Q