$prev = ($i == 0) ? $total : $i-1; fuck off, i love you : Dan Wilton