View Single Post
  #6 (permalink)  
Old 08-03-2009, 07:29 PM
admin admin is offline
Administrator
Site Admin
 
Join Date: Sep 2003
Posts: 2,689
Default count in forloop

One simple optimization that most people miss is not using count($var) as a condition of for loops.


PHP Code:
// Wrong
for ($i 0$i count($Results); $i++)
{
// Do Something


PHP Code:
// Correct
$ResultCount count($Results);
for (
$i 0$i $ResultCount$i++)
{
// Do Something

It’s very simple, and now you’re not counting the size of the stack every time you process the loop.
__________________
BizHat Games BizHat Video
Reply With Quote