$prev = ($i == 0) ? $total : $i-1; zuul / vice : Dan Wilton