On Thu, 2010-01-28 at 00:08 +0800, Eric Lee wrote: > On Wed, Jan 27, 2010 at 11:44 PM, Ashley Sheridan > <ash@xxxxxxxxxxxxxxxxxxxx>wrote: > > > On Wed, 2010-01-27 at 10:42 -0500, Paul M Foster wrote: > > > > > "... should be obvious - but are often overlooked - points within coding > > > practice that can cause the programmer to develop bad habits and bad > > > code." - Dan Brown > > > > > > Tip #1: > > > > > > Don't use count() in loops unless there are very few items to count and > > > performance doesn't matter, or the number will vary over the loop. That > > > is, don't do this: > > > > > > for ($i = 0; $i < count($items); $i++) > > > > > > Instead, do this: > > > > > > $number = count($items); > > > for ($i = 0; $i < $number; $i++) > > > > > > Reason: when you use the count() call at the top of the loop, it will > > > re-evaluate the number of items each time it's called, which usually > > > isn't necessary and adds time. Instead, work out the number of items > > > before going into the loop and simply refer to that for the number of > > > items in controlling the loop. > > > > > > Paul > > > > > > -- > > > Paul M. Foster > > > > > > > > > What about using the right type of quotation marks for output: > > > > I use double quotes(") if I expect to output variables within the > > string, and single quotes when it's just a simple string. > > > > It's only a general rule of thumb and shouldn't be adhered to > > absolutely, but I remember a thread a while back that showed the speed > > differences between the two because of the extra parsing PHP does on > > double quoted strings. > > > > > That should be on the stackoverflow.com > It compare the string parsing with or without variables embeded > and the important of comma operator when ` echo ` data > > use > echo 'something', 'other' > > but not > echo 'something' . 'other' > > > Eric, > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > > There is a big difference between using a comma and a period. A period (.) actually concatenates the strings, whereas a comma only adds it to the echo stream. So, if you were trying to assign the joining of the two strings to a variable, you would have to use a period, as the comma would throw a syntax error. Thanks, Ash http://www.ashleysheridan.co.uk