Diegar Posted October 9, 2007 Share Posted October 9, 2007 If i have a string with a value of "name0", is there a way to turn it into a string named $name0? Link to comment Share on other sites More sharing options...
Synook Posted October 9, 2007 Share Posted October 9, 2007 Use the eval function: $string = "name0";eval("\$$string = \"Whatevertext\";");echo $name0; //Will echo "Whatevertext" Link to comment Share on other sites More sharing options...
Diegar Posted October 9, 2007 Author Share Posted October 9, 2007 That worked. Thank you very much! Link to comment Share on other sites More sharing options...
justsomeguy Posted October 9, 2007 Share Posted October 9, 2007 You don't even need to use eval, you can use two $ symbols to reference a variable variable:$varname = "name0";$$varname = "test";echo $name0; Link to comment Share on other sites More sharing options...
Synook Posted October 10, 2007 Share Posted October 10, 2007 indirection - I never knew you could do that in PHP Link to comment Share on other sites More sharing options...
justsomeguy Posted October 10, 2007 Share Posted October 10, 2007 Yeah, you can have all kinds of fun with that.http://www.php.net/manual/en/language.variables.variable.php Link to comment Share on other sites More sharing options...
user4fun Posted October 12, 2007 Share Posted October 12, 2007 never knew thw word fun and php couldbe in the same sentence, lol Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.