photos as $p) { if($image == $p->file) { $photo = $p; } if($image == $last->file) { $next = $p; break; } $prev = $last; $last = $p; } ?>