3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* for each month i 6monthAvg = round( ( ( $profits[$i] +((isset($profits[$i-1])) ? $profits[$i-1] : 0) +((isset($profits[$i-2])) ? $profits[$i-2] : 0) +((isset($profits[$i-3])) ? $profits[$i-3] : 0) +((isset($profits[$i-4])) ? $profits[$i-4] : 0) +((isset($profits[$i-5])) ? $profits[$i-5] : 0))/6),2); for($i = 5, $length = count($months); $i < $length; $i++) { echo round(array_sum(array_slice($months, $i, -6), 2); } foreach(array_chunk($months, 6) as $sixMonths){ if(count($sixMonths) == 6) echo round(array_sum($sixMonths), 2); else echo "Not 6 months avilable"; } */ print_r(array_slice([1,2,3,4,5,6], 5, -6));

preferences:
46.48 ms | 402 KiB | 5 Q