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? Link to comment https://forums.phpfreaks.com/topic/186546-variables-for-loop/ 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 Link to comment https://forums.phpfreaks.com/topic/186546-variables-for-loop/#findComment-985188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.