briant Posted September 25, 2006 Share Posted September 25, 2006 $num = 1;$test$num = "blah blah";print $test1;$test$num, how can i have 2 variables stuck together?I tried adding a period $test.$num but that didn't work. Link to comment https://forums.phpfreaks.com/topic/22011-2-variables-stuck-together/ Share on other sites More sharing options...
wildteen88 Posted September 25, 2006 Share Posted September 25, 2006 Do you want to create a variable which is called what $test holds and add $num to the name. For example:$test - holds myvar$num - holds the number 1You can to create a variabled valled myvar1You'll do this:[code=php:0]${'myvar' . $num} = 'blah blah';// echo the variable that was created above.echo $myvar1;[/code] Link to comment https://forums.phpfreaks.com/topic/22011-2-variables-stuck-together/#findComment-98377 Share on other sites More sharing options...
briant Posted September 25, 2006 Author Share Posted September 25, 2006 I LOVE YOU FOREVER! Thanks so much, exactly what I was looking for. Wildteen88, you are da bomb, always helping everyone out. Thanks again Link to comment https://forums.phpfreaks.com/topic/22011-2-variables-stuck-together/#findComment-98378 Share on other sites More sharing options...
wildteen88 Posted September 25, 2006 Share Posted September 25, 2006 I forgot the test var. This is what my example should be:[code=php:0]$test = 'myvar';$num = 1;${$test. $num} = 'blah blah';// echo the variable that was created above.echo $myvar1;[/code]However its stull the same. Just that I had myvar 'hardcoded' in. Link to comment https://forums.phpfreaks.com/topic/22011-2-variables-stuck-together/#findComment-98383 Share on other sites More sharing options...
Barand Posted September 25, 2006 Share Posted September 25, 2006 However, instead of constructing varables with names like "$myvar1", "$myvar2" and having[code]$myvar1 = 'blah';$myvar2 = 'blah blah';[/code]it's a lot easier and more convenient to store in an array[code]$myvar = array();$myvar[1] = 'blah';$myvar[2] = 'blah blah';[/code] Link to comment https://forums.phpfreaks.com/topic/22011-2-variables-stuck-together/#findComment-98396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.