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;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!