比较foreach的值

I want to check if the value of $first[0] in each foreach is unique or does already exists in another foreach. But I have to compare it outside of the foreach.

Is this possible?

<?php foreach($instagram_array['items'] as $image) { ?>
    <div class = "tag" >
        <img src = "<?php echo $image['images']['low_resolution']['url'] ?>" width = "250px" >
        <?php
            $first = explode(" ", $image['caption']['text']);
            echo $first[0];
        ?>
    </div>
<?php } ?>