Home arrow PHP arrow Using Variable Variables in PHP

Using Variable Variables in PHP

Quite possibly one of PHP’s least utilized yet most valuable features is its support for Variable Variables. In short these are a method of using the value of one variable to call the name of another. Sound confusing? We'll explain everything...

  1. Using Variable Variables in PHP
  2. Variable Variables?
  3. Using Variable Variables with Arrays
  4. Variable Variables with Functions
  5. Variable Variables with Classes
  6. The Never-ending Variable
  7. Conclusion
By: Eric Seufert
Rating: starstarstarstarstar / 15
February 14, 2001

print this article


Quite possibly one of PHP’s least utilized yet most valuable features is its support for Variable Variables. I stumbled across this concept just recently while working on a "Fiction Portal" project for a gaming website. Users of the service could submit their own fictional stories to a program which would then dump them into a MySQL table and populate that table’s columns with the characteristics of the story that the author provided. The way the table had been setup was such that each possible characteristic of a story was a separate column, and each story that held that characteristic would hold a value of 1 in the column whereas each story that didn’t would hold a value of 0 in it. Therefore, a sample story might look like this in the table:

Author Title Date Horror Comedy Adventure Test "Test Story" 1/1/01 0 0 1

Everything went smoothly until I discovered that this method of sorting made searching for stories with only certain criteria nearly impossible. Cue Variable Variables.

>>> More PHP Articles          >>> More By Eric Seufert

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: