dammyg Posted September 23, 2008 Share Posted September 23, 2008 Hi, probably very simple but just wondering how to echo out something like below: eg: $variable="echothisvariable"; //i want to echo $echothisvariable Thank You Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/ Share on other sites More sharing options...
ratcateme Posted September 23, 2008 Share Posted September 23, 2008 $variable="echothisvariable"; echo $variable; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648414 Share on other sites More sharing options...
dammyg Posted September 23, 2008 Author Share Posted September 23, 2008 Hi, I am trying to echo like this: echo $(echo $variable;); Thank You Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648423 Share on other sites More sharing options...
genericnumber1 Posted September 23, 2008 Share Posted September 23, 2008 it's terrible practice and you should use arrays, but you CAN technically do echo $$variable; but I wouldn't advise it. Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648426 Share on other sites More sharing options...
ratcateme Posted September 23, 2008 Share Posted September 23, 2008 what about $variable="echothisvariable"; $echothisvariable = "this is to be echoed"; echo $$variable; Scott. Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648427 Share on other sites More sharing options...
Zane Posted September 23, 2008 Share Posted September 23, 2008 then it would echo "this is to be echoed" nothing special Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648447 Share on other sites More sharing options...
F1Fan Posted September 23, 2008 Share Posted September 23, 2008 Are you trying to do this: <?php $variable="echothisvariable"; ${$variable} = "this is to be echoed"; echo ${$variable}; ?> That would set and echo the variable $echothisvariable. Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648635 Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 Or do you want it like this? $echo = '$variable="echothisvariable"'; echo $echo; ??? Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648638 Share on other sites More sharing options...
F1Fan Posted September 23, 2008 Share Posted September 23, 2008 I feel like we're playing charades! Um... two words, first word ECHO! Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648639 Share on other sites More sharing options...
Zane Posted September 23, 2008 Share Posted September 23, 2008 well it's extremely...obvious by now that the guy is looking at Variable Variables. so...I win Quote Link to comment https://forums.phpfreaks.com/topic/125411-echo-the-variable-of-a-value-of-a-variable/#findComment-648686 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.