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? Link to comment https://forums.phpfreaks.com/topic/104249-variable-issue/ Share on other sites More sharing options...
947740 Posted May 5, 2008 Share Posted May 5, 2008 Does that now work? Link to comment https://forums.phpfreaks.com/topic/104249-variable-issue/#findComment-533692 Share on other sites More sharing options...
gple Posted May 5, 2008 Author Share Posted May 5, 2008 no Link to comment https://forums.phpfreaks.com/topic/104249-variable-issue/#findComment-533701 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.. Link to comment https://forums.phpfreaks.com/topic/104249-variable-issue/#findComment-533703 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. Link to comment https://forums.phpfreaks.com/topic/104249-variable-issue/#findComment-533705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.