From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Variable variables

Variable variables

- [Narrator] Hi, I'm David Powers and welcome to this week's edition of PHP Tips, Tricks and Techniques, designed to help you become a smarter, more productive PHP developer. This time, I'm going to look at a powerful concept known as variable variables. Yes, they really exist, I'm not just repeating myself. With an ordinary variable, the name of the variable is always the same. It's only the value that ever changes. With a variable variable, on the other hand, it's not only the value that can change, the name of the variable can also be changed dynamically. This can be useful in situations where the same code needs to be executed over and over again by different variables. So how do you create a variable variable? Well, you start with an ordinary variable. Let's call it a. Assign it a string as it's value. This will be used as the variable variable's name. So it can't contain any spaces or special characters other than an underscore and it can't begin with a number. You create a…

Contents