Learn how PHP's variable variables allow you to change the variable name dynamically on the fly, which can be useful when the same code needs to be applied to different elements.
- [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 variable variable from a…by preceding it with a second dollar sign…
Note: The exercise files are free to all members. The code is commented to enhance your learning, but you will need database connectivity for some files to run as intended.
Skill Level Intermediate
PHP: Managing Persistent Sessionswith David Powers2h 41m Intermediate
New this Week:
1. Weekly Episodes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.