I overcame my problem by adding a
$count = 0;
outside my for each.
I then added this line where I wanted, or didn’t want, a <hr /> tag:
if( ($count + 1) < (count($lastposts)) ) { ?><div class="clear"><hr /></div><?php }
and then obviously added:
$count++
before the end of the foreach loop