Run The Loop over array of post objects

I’m using this in one of my custom widgets:

global $post;
$posts = array( /* WP_Post, WP_Post, ... */);
while (list($i, $post) = each($posts)) :
    setup_postdata($post);
    // use the template tags below here
    if(has_post_thumbnail()):
        ?><div class="featured_image_wrap"><?php
            the_post_thumbnail();
        ?></div><?php
    endif;
    the_title();
endwhile;
// don't forget to restore the main queried object after the loop!
wp_reset_postdata();