aebstract Posted May 2, 2010 Share Posted May 2, 2010 What's the method for creating a variable using another variable in the name of it? For instance: for ($variable = 1; $variable <= 9; $variable++) { I want to create the following: $var1 $var2 $var3 etc The number being generated off of "$variable" Quote Link to comment https://forums.phpfreaks.com/topic/200463-create-variable-name-with-variable-in-it/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 That is just a bad idea. Use an array or something. But if you must, ${"var".$variable}. Quote Link to comment https://forums.phpfreaks.com/topic/200463-create-variable-name-with-variable-in-it/#findComment-1051972 Share on other sites More sharing options...
Zane Posted May 2, 2010 Share Posted May 2, 2010 for($variable = 0; $variable ${"var" . $variable} = $variable; Quote Link to comment https://forums.phpfreaks.com/topic/200463-create-variable-name-with-variable-in-it/#findComment-1051973 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.