Porl123 Posted September 18, 2010 Share Posted September 18, 2010 How would I output the value of a variable, getting the name from the value of another variable? For example: $var1 = 'var2';$var2 = 'output'; I want it to return 'output', which I'd imagine would work through entering something along lines of $$var1; Does anyone know what I mean? Link to comment https://forums.phpfreaks.com/topic/213725-problem-with-variables/ Share on other sites More sharing options...
MadTechie Posted September 18, 2010 Share Posted September 18, 2010 Yep, a variable variable, not much of a question as you also posted the answer Example $var1 = 'var2';$var2 = 'output';echo $$var1; Link to comment https://forums.phpfreaks.com/topic/213725-problem-with-variables/#findComment-1112428 Share on other sites More sharing options...
Porl123 Posted September 18, 2010 Author Share Posted September 18, 2010 Ah yeah, I already tried that and it didn't work. I've just realised that another part of my script near the top was killing the page. :x Thanks! Link to comment https://forums.phpfreaks.com/topic/213725-problem-with-variables/#findComment-1112429 Share on other sites More sharing options...
PFMaBiSmAd Posted September 18, 2010 Share Posted September 18, 2010 You will find that in almost every case, using an array will result in simpler code. It will be faster too, because setting or referencing a variable using a variable variable is three times slower than using an array variable directly. Link to comment https://forums.phpfreaks.com/topic/213725-problem-with-variables/#findComment-1112431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.