PHP: How do I limit the amount of results in an array : <p>I am pulling trends out of the Twitter API. I end up with an array with 42 items. I can print the elements I want just fine, however I would like to limit the amount of elements to just 5 instead of 42.</p>

<p>Here's a screenshot of the data returned:</p>

<p><a href="https://i.stack.imgur.com/BY1Uk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BY1Uk.png" alt="enter image description here"></a></p>

<p>Here's my foreach loop that grabs the element I want (name):</p>

<pre><code>foreach ($string[0]['trends'] as $trend) {

    echo $trend['name']."&lt;br /&gt;";

}
</code></pre>

<p>How do I print only the first 5 elements ([name])?</p>
