One of my favorite things to do when writing code is to make functions that do more than one thing so instead of having 10 different functions I have 1, maybe 2, that can do the same. Part of the reason I code like this is for the challenge, and the other reason is so that when I make changes I don’t have to rely on find & replace but I can simple make my change once or twice (or add code) and not have to make sure I don't break 1 or 2 of the 10 functions.
That''s where variable variables come into play. Check out the write up for Variable Variables on php.net.