Wordpress数组不能按标题过滤

I'm having difficulty removing duplicate posts from a Wordpress query. Unfortunately, the duplicate posts all have identical content but their ids are different. So I've been trying to build an array of title values and checking against that. I am unable to add to the array each time through, it resets for each post.

****EDITED****

Right now I'm just trying to get the array working properly. Once the array is working properly, I can test to see if the title of the current post is in the array and if it is, skip it.

****EDITED****

I've taken the suggestions and stripped the issue down to its essentials.

archive.php:

<?php get_header(); ?>
    <div class="grid">
        <div class="grid-col">
            <?php if (have_posts()) { ?>
                <ul>
                    <?php while (have_posts()) {
                        the_post();
                        get_template_part( 'inc/single', 'location' );
                        }
                    ?>
                </ul>
            <?php
                } else {
                get_template_part( 'content', 'none' );
                }
            ?>              
        </div>
   </div>
<?php get_footer(); ?>

single-location.php:

<?php
$do_not_duplicate = array(); 
$id = get_the_ID();
$contacts = getLocationContact($id, false); 
?>
<?php
foreach($contacts as $locationData): 
$title = esc_html($locationData['title']);
$do_not_duplicate[] = $title;
?>     
<li>
    <div>
        <h3><?php echo esc_html($locationData['title']); ?></h3>
    </div>
</li>           
<?php  endforeach; ?>