Best performance: count in a loop or outside? : <p>Perhaps this question has been asked several times but I can't find a proper answer here or in Google so apologies if this is a dupe or something like that but here I go... </p>

<p>What's the best way to achieve performance in a loop:</p>

<ol>
<li><p><code>count($var)</code> each time</p>

<pre><code>for ($i=0;$i&lt;count($var);$i++) {
    // do something
}
</code></pre></li>
<li><p>put a var outside and use that var:</p>

<pre><code>$cnt = count($var);
for ($i=0;$i&lt;$var;$i++) {
    // do something
}
</code></pre></li>
</ol>

<p>Is there any PHP script or code to show execution times and so on? I mean something for benchmark and see the results on this cases?</p>
