Re: Pointers For Newbies, Reminders For Oldies
| From: | Michael A. Peters | Date: | Wed, 27 Jan 2010 16:01:39 +0000 |
| Subject: | Re: Pointers For Newbies, Reminders For Oldies | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-301554@lists.php.net to get a copy of this message | ||
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++)Gah! for ($i=0;$i<sizeof($array);$i++) is something I do all the time. So the array size is being calculated each iteration?