<?php
$previousDay = null;
foreach ($days as $day) {
if(isset($previousDay)) {
// Do the calculations with $day being the current one and prevDay the previous day (night?)
} else {
// For the first day of the array you have no previous so do normal calculations or smth
}
$previousDay = $day;
}