|
Posted by Rik on 10/19/06 06:29
Chung Leong wrote:
> Sonnich wrote:
>> So, which is faster:
>>
>> for($j = 0;$j<count($array);$j++)
>> or
>>
>> $j = 0
>> while($j<count($array))
>> $j++;
>>
>> (well, I know that counting down is faster, so...
>>
>> $j = count($array)-1;
>> while($j>=0)
>> $j--;
>> )
>
> They're both slow. foreach() is the fastest.
Very true indeed.
Then again, the looping is often not the problem, more the actual logic
that is performed within the loop. If you need looping, you need looping,
no denying that. The logic inside the loop however, often has very useless
duplicate assigments etc. When looping, be sure to set everything not
related to the loop outside that particular loop.
That seems very obvious, but I cannot count the times I've seen loops with
identical assignments over and over again.
--
Rik Wasmus
Navigation:
[Reply to this message]
|