One thing you should NOT do with PHP

I know how dangerous it is, but it’s out of habit. What am I talking about? Well, it’s probably one of the most common mistakes a PHP developer/programmer/user will find: an array in a loop. It happens to me all the time, no matter what I’m working with, let it PHP, Python or JavaScript. This is just a reminder to me and anyone who faces this problem: never build an array in a loop! The array will just overwrite itself, and it can be a very well hidden problem. This includes loops and nested loops (loops in loops)… unless you want the array to overwritten. There are instances where the array needs to be overwritten (the mysql_fetch_assoc function is a good example).

This whole post may sound silly, but I suggest you be careful with array building in loops! it won’t cause any major problems (with exceptions), but you will never get the result you want (unless you want to the array to be overwritten, like I said before).

Drieick

Share and Enjoy:
  • Digg
  • Reddit
  • StumbleUpon
  • del.icio.us
  • Technorati
  • Facebook
  • Mixx
  • Google
  • TwitThis

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!


Drieick I. Am. Da kine. Read more from this author


Tags: , , , , , , , , , August 18th, 2008 Posted in Computers, PHP, Pantsu

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress | Blue Weed by Blog Oh! Blog | Entries (RSS) and Comments (RSS).