[MUST READ] The Fastest For (Improve your PHP!)

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

That's probably because English isn't their native language.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Yeah, I saw the TLD, but still, there's no explanation for the other quote.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

AKA Panama Jack wrote:You should NEVER use the COUNT function in a FOR loop

Code: Select all

for ($i=0; $i < count($array); $i++) {}
Never? What about when you want count() executed every loop becaue you are changing the length of the array within the loop?

I agree it should not be used when iterating over the entire array. But never? ;)

I would also like to note that the speed of the loop instruction is often an insignificat part of the time it takes to execute the instructions within the loop.
(#10850)
User avatar
Hades
Forum Commoner
Posts: 35
Joined: Mon May 08, 2006 4:49 pm

Post by Hades »

foreach will likely be faster due to the fact that it essentially does the same as you are doing in the for loop, but it is written in C and that makes it faster to execute ;)
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Hades wrote:foreach will likely be faster due to the fact that it essentially does the same as you are doing in the for loop, but it is written in C and that makes it faster to execute ;)
All of PHP is written in C. What's the point you're making?
Post Reply