March 23, 2012
PHP advice: To be or not to be Variable Variables
Question by matt
is it useful to implement variable variables in PHP?
(Try not to leave this post just with a yes/no answer. The importance here, and for what I’m asking, is about the fundamentals of your opinion.)
Thanks!
Answer by Starx
Depends entire upon the requirement of the application.
I will give you a scenario
$array = array(1,2,3,4,5,6,7,8); //This array holds the number of time you have been on the mission
$month1 = "January"; //this holds when it happened
$month2 = "March";
//Now, the colonel might want to know when the mission happened
foreach($array as $value) {
$v = "month".$value;
echo $$v;
}