Storing a PHP loop as a string in a variable

frank

New Member
I have a problem storing a PHP loop in a variable.The loop is like this:\[code\]for( $i = 1; $i <= 10; $i++ ) { echo $i . ' - ';}\[/code\]for this it's OK for an \[code\]echo\[/code\] or \[code\]print\[/code\] as it will produce:\[quote\] 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 -\[/quote\]now I want to store the whole loop in a variable like \[code\]$my_var\[/code\] which means:\[code\]echo $my_var;\[/code\]which will produce:\[quote\] 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 -\[/quote\]the whole idea is that I want to make the loop, store it as a string in a variable \[code\]$my_var\[/code\], than use it later in my script.I hope the idea is clear. Thanks.
 
Back
Top