Although the use of the array shortens the amount of code produced, it does have the slight overhead of the math to calculate the position of the next element. The code snippets are pseudo code, and very simplified, but it's just to give an idea of what is produced by the interpreter/compiler.
For myself, I prefer using an array system. Because it keeps code more compact. When you been around for awhile and see if/else...switch/case statements hitting 30-50 blocks. and trying to fix/update the code becomes a chore.
My rule of thumb is never to use more than 3-5 if/else...switch/case statements. At this point consider using an array system.
New coders often find using arrays difficult so postpone learning them.
Another good rule of thumb is to code for maintainability first, and worry about performance only if and when you find that you have to. (More often than not, your main performance bottlenecks will be the database, not your PHP code -- unless it's really, really awful ). That's not to say you shouldn't think about code efficiency at all, but I'd rather worry about saving hours of debugging versus microseconds of performance.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks