Get only the first result of a foreach loop
<p>I am trying to display all the links that are located in <code>&lt;div class="post"&gt;</code>. There are many <code>&lt;div class="post"&gt;</code> inside my page (it is a blog). However there are many links in every <code>&lt;div class="post"&gt;</code> but I want to display the first of every div. 
My question is how can I limit my code to show only the first one and continue to the next div?
Below is my code that gets and displays all the links. Gracias!</p>

<pre><code>&lt;?php
$dom = new DOMDocument;
libxml_use_internal_errors(TRUE);
$dom-&gt;loadHTMLFile('http://www.mydomain.com/');
libxml_clear_errors();

$xPath = new DOMXPath($dom);
$links = $xPath-&gt;query('//div[@class="post"]/a/@href');
foreach($links as $link) {
    printf("%s \n", $link-&gt;nodeValue);
}
?&gt;
</code></pre>
