Re: foreach() faster than while()?

From: Date: Wed, 14 Mar 2001 16:20:45 +0000
Subject: Re: foreach() faster than while()?
Groups: php.general 
Request: Send a blank email to php-general+get-43865@lists.php.net to get a copy of this message
I meant to write about this last week! I see a LOT of examples on the PHP website, both by contributions and by the staff responsible for the manual, of using functions inside of loops to get a value that doesn't change, i.e. the end or beginning of an array. A lot of code out there would speed up tremendously if the necessary value was stored in a temporary variable, which would then be used in the loop. Probably, using echo() or print() in a loop also slows things down, buffering into a variable first is much faster, I bet. One thing I've taken to doing that is related to this, is any object method() that would normally have a printed output, I make two output functions, 'getValue()' and 'printValue()'. the getValue() buffers to a variable in the object and this can be used inline in another place thats buffering output. If I want it printed right away, the printValue() calls getValue(). And because I like readable web page HTML, I also have begun to start including an 'indention' argument to those functions, or sometimes an 'indention' attribute. At the beginning of the buffering and also following a '\n' in the HTML being buffered, I place the number of spaces to cause proper indention in the HTML output to make tables etc line up. It does make the files a little bigger, but it's lot's easier to see what's going on in the code. I suppose if I wanted to, I could make a global variable that said, 'INDENTION_ON/OFF' for production.

« previous php.general (#43865) next »