redarrow Posted March 6, 2006 Share Posted March 6, 2006 Can someone exspaian what the double varable varables doller sign for, and how to use it, An example would be grate cheers.examples//assign a varable is $john='house';//echo varable is echo $john;// how to use this double varable method please thank you.$$whateverAdvance thank you Quote Link to comment https://forums.phpfreaks.com/topic/4175--/ Share on other sites More sharing options...
Sasuun Posted March 6, 2006 Share Posted March 6, 2006 I don't think $$ means anything, or that it would really matter if it did. all a variable does is store data, if there is a variable defined with $$ it would function the same as one defined with only one $most likely, however, while $john is the var john, $$variable is the variable $variable. Quote Link to comment https://forums.phpfreaks.com/topic/4175--/#findComment-14496 Share on other sites More sharing options...
neylitalo Posted March 6, 2006 Share Posted March 6, 2006 I think this is how it would work.Say you have a variable called $name. [code]$name = "john";[/code]And say you want to assign the NAME of another variable based on $name. I honestly don't know why you'd want to, but you do. :)You can then do this:[code]$$name = "male";[/code]It puts the contents of $name ("john") in place of "$name", so you effectively have:[code]$john = "male";[/code]So now you can work with the variable $john. Quote Link to comment https://forums.phpfreaks.com/topic/4175--/#findComment-14498 Share on other sites More sharing options...
ToonMariner Posted March 6, 2006 Share Posted March 6, 2006 Variable variables (as they are called) can be very useful.neylitalo has the basics correct....$var = 'name';creates a container so you can vary the varibale usedso echoing $$var would echo out the contents of $name.It becomes really useful looping through similar variables like so..say you have lots of variables called:foo1, foo2, foo3....foo4now you don't have any array to loop through as they are all independant vars as far as php is concernedBUT if you do this$i = 1;do { $var = 'foo$i'; echo $$var; $i++;} while ($$var);that would echo out each and every variable fooNUMBER. Quote Link to comment https://forums.phpfreaks.com/topic/4175--/#findComment-14503 Share on other sites More sharing options...
redarrow Posted March 6, 2006 Author Share Posted March 6, 2006 so $john="john";$john="male";adding the first douler sign gives john and then john turns into another varable to add $john as male.i think i go that right thank you.[!--sizeo:6--][span style=\"font-size:24pt;line-height:100%\"][!--/sizeo--]solved[!--sizec--][/span][!--/sizec--]correted echo $$john; Quote Link to comment https://forums.phpfreaks.com/topic/4175--/#findComment-14504 Share on other sites More sharing options...
ToonMariner Posted March 6, 2006 Share Posted March 6, 2006 no. [code]$name = 'john';$var = 'name';echo $name; // outputs 'john'echo $var; // outputs 'name'echo $$var; // outputs john$name1 = 'john';$name2 = 'pete';$i = 1;$var = 'name$i';do {echo $$var . "<br>";$i++;} while ($$var);// this will output..johnpete[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4175--/#findComment-14508 Share on other sites More sharing options...
redarrow Posted March 6, 2006 Author Share Posted March 6, 2006 Thank you for your time but i dont understand looping yet but thank you.$i = 1;// assign name 1 and name 2 to john and pete.$name1 = 'john';$name2 = 'pete';//assign $i to a 1$i=1;// assign $var to name$i and $i$var = 'name$i';//do somethink and bracedo {//echo $$var with brakeecho $$var . "<br>";// $i plus 1 more$i++;//close brace while $$ is var} while ($$var);will print john and petetry to understand lol Quote Link to comment https://forums.phpfreaks.com/topic/4175--/#findComment-14511 Share on other sites More sharing options...
neylitalo Posted March 6, 2006 Share Posted March 6, 2006 [!--quoteo(post=351941:date=Mar 5 2006, 07:54 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Mar 5 2006, 07:54 PM) [snapback]351941[/snapback][/div][div class=\'quotemain\'][!--quotec--] Variable variables (as they are called) can be very useful.neylitalo has the basics correct....$var = 'name';creates a container so you can vary the varibale usedso echoing $$var would echo out the contents of $name.It becomes really useful looping through similar variables like so..say you have lots of variables called:foo1, foo2, foo3....foo4now you don't have any array to loop through as they are all independant vars as far as php is concernedBUT if you do this$i = 1;do { $var = 'foo$i'; echo $$var; $i++;} while ($$var);that would echo out each and every variable fooNUMBER. [/quote]That's the only thing I can see it coming in handy for. However, there is an easier way. Now, I'm not saying your method is wrong, but I want to point out one little thing.Why not just create an array? ;) Call it $foo, and have the keys be numbers. And you can do so much more stuff with arrays. foreach loops, sorting, the whole nine yards.And quite honestly, I don't see ANY situation where it would be easier to have a bunch of variables than a single array with several keys. Quote Link to comment https://forums.phpfreaks.com/topic/4175--/#findComment-14541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.