galvin Posted January 5, 2010 Share Posted January 5, 2010 I have a variable whose ending number will change, like... $byesleft_user_1 $byesleft_user_2 $byesleft_user_3 etc, etc. How can I use $i in place of that number. I tried $byesleft_user_{$i} but that isn't working. Anyone know the proper syntax? Quote Link to comment https://forums.phpfreaks.com/topic/187197-variable-within-a-varible-question/ Share on other sites More sharing options...
mikesta707 Posted January 5, 2010 Share Posted January 5, 2010 The following should give you a clue of how to do it $rand1 = "d"; $rand2 = "c"; $rand3 = "x"; for($i = 1; $i < 4; $i++){ $varName = "rand".$i; echo $$varName . "<br />"; } output: d c x Quote Link to comment https://forums.phpfreaks.com/topic/187197-variable-within-a-varible-question/#findComment-988512 Share on other sites More sharing options...
oni-kun Posted January 5, 2010 Share Posted January 5, 2010 The above is another method of passing the variable into another, but as for your original question you should do something like this: ${"byesleft_user_".$i} Quote Link to comment https://forums.phpfreaks.com/topic/187197-variable-within-a-varible-question/#findComment-988514 Share on other sites More sharing options...
galvin Posted January 5, 2010 Author Share Posted January 5, 2010 THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/187197-variable-within-a-varible-question/#findComment-988526 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.