gple Posted May 5, 2008 Share Posted May 5, 2008 for ($i=0;$i<10;$i++) { $seed.$i=$array[0]; } i want to assign 10 variables ($seed0 through $seed9). How do i do that with the above? Quote Link to comment Share on other sites More sharing options...
947740 Posted May 5, 2008 Share Posted May 5, 2008 Does that now work? Quote Link to comment Share on other sites More sharing options...
gple Posted May 5, 2008 Author Share Posted May 5, 2008 no Quote Link to comment Share on other sites More sharing options...
flyhoney Posted May 5, 2008 Share Posted May 5, 2008 You cannot concatenate variable names like that. $this.$that = 'something' Does not work. You have to actually assign them all. $seed0 = $array[0] $seed1 = $array[1] etc.. Quote Link to comment Share on other sites More sharing options...
phorman Posted May 5, 2008 Share Posted May 5, 2008 This is how you would accomplish the task. <?php for ($i=0;$i<10;$i++) { $seed = "seed$i"; $$seed =$array[0]; } ?> The part that makes this possible is that two "$" dollar signs together will form a variable name with the string contained in the second $ variable. I do however question the need for this in this example as any variable with numbers assigned after it should be stored in an array to make it easier to loop, sort, or move the variables around if necessary. Quote Link to comment 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.