Forum Moderators: coopster
$user ="bob";
$holder="user";
print $$holder;
$user ="bob";
print $user;
so why in example one would you have to use $$holder? why can't $holder work?
also, what is the point in writing it in the way that example on is written? an example for that would be helpful.
thanks guys, sorry i'm a n00b :)
I usually use the ${$a} style. I use them for creating dynamic numbers of arrays etc.
FYI - javascript_string is a little function that rewrites a string in to be used in javascript functions later - makes quotes and html code safe.
$array = array('time','comment','name','venname','start','name2');
foreach ($array as $val) {
javascript_string($$val);
}
A lot shorter than the alternative syntax...
javascript_string($time);
...
this is a case from a switch that I use (it's a little lazy ;)) this one case handles the display of content based on multiple vars but this little guy with the variable vars does it all for me. Makes code confusing sometimes but it works really well. In this particular case if I didn't use them the code would be, at least, 5 times the size.
I use a var to name the array(s) of "stuff" attributed to it. I can then use that single var to connect all the data together. Before this above case is executed there is a lot of calculation done so I create the arrays as I go and use the "parent" var to display.
Variable variables are useful for repetition.
<added>
i guess i'm stupid
sorry to burst your bubble but you're not :)
I had one heck of a time keeping them straight the first time I used them. With out a specific situation where they are needed it is hard to wrap your head around them.