This is our "Three Write Rule"
Write your code three times.
What we mean is that start as you normally would — however you personally like, until your code works.
Then delete it and write it again in a different way — change the interface, perhaps; use an array perhaps; change an array to an associative array perhaps. Just change it. And get it working again.
Then delete it and write it again.
The third and final version will be the better.
Notes
1. Actually, in some cases, this need not happen if one "gets it right" the first or second time when the code is small.
2. Or, in some cases, the fourth, fifth, sixth...