PHP Arrays

Last week at work I was asked to add a feature to an existing website that we host. The base code for this website was written years ago with register_globals assumed to be on or registered automatically. That and the horrible code aside, I decided not to mess with any of it and just write my own little section of code that did what it needed to and drop it in to the site. I’m not sure if that was the best idea from a design stand point, but his code was not commented at all and the variable/function names were not descriptive of what they stored or did in the least. It would have taken me days if not weeks just to figure out what everything did.

All that aside, while writing the module they asked me to write I was faced with the problem of making sure an array always has the same number of entries in it. What it does is pull information from a database and display a static number of those entries. Keeping that limited to a static number was not a problem, however what if there weren’t that many entries in the database? How do I go back through the array and populate it with static information? This is what I came up with.

When I first got this written and working I was quite proud that I had gotten it to work. Then I got to thinking about it and it just seems like there should be a better way to do such a thing. I did some research online but I couldn’t find anything on that particular subject. Anyone out there got any ideas?

Popularity: 1% [?]

0 Responses to “PHP Arrays”


Comments are currently closed.