if single word already output, continue
<p>I'm very new in PHP, and would like to do a foreach loop that won't repeat a result if the same item has been output before.</p>

<p>Here's my code:</p>

<pre><code>    foreach ( $attachments as $id =&gt; $attachment ) {
        echo ($attachment-&gt;post_title);
    }
</code></pre>

<p>As you can see, the word would be pulled by <code>echo ($attachment-&gt;post_title);</code>.</p>

<p>Is there a way to do some checking and avoid duplicates?</p>

<p>Many thanks for your help.</p>
