I have a problem storing a PHP loop in a variable.
The loop looks like this:
for( $i = 1; $i <= 10; $i++ ) {
echo $i . ' - ';
}
for this, it is OK for echoor print, as it will produce:
1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 -
now I want to save the whole loop in a type variable $my_var, which means:
echo $my_var;
which will produce:
1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 -
the whole idea is that I want to make a loop, save it as a string in a variable $my_var, than use it later in my script.
source
share