gple Posted December 29, 2009 Share Posted December 29, 2009 how do i assign a different variable through each for loop for ($i=0;$i<10;$i++) { $variable.$i="test"; } echo $variable0; how would I output Test? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 29, 2009 Share Posted December 29, 2009 You must assign a dynamic variable as so: <?php $variable = ''; for ($i=0;$i<10;$i++) { ${"variable{$i}"} = 'test'; } echo $variable0; ?> You can read more about it here: http://php.net/manual/en/language.variables.variable.php 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.