How would one go about echoing a variable multiple times..
A way to understand this question better would be if I said:
$foo = '<div>bar</div>';
echo $foo*7;
It's probably the most simple thing, but I'm not sure.
And
In this simple case, you can use str_repeat()
.
$foo = '<div>bar</div>';
echo str_repeat($foo, 7);
Reference: PHP string functions
For anything more complex, a loop is usually the way to go.
Use a for
loop.....................
for ($i = 0, $i <= 7, $i++) {
echo $foo;
}
Use str_repeat()
.
echo str_repeat($foo, 7);
Don't multiply strings. You can either do it manually:
echo $variable;
echo $variable;
echo $variable;
echo $variable;
// etc
Or in a for loop:
for($z=0;$z<10;$z++){
echo $variable;
}
Or str_repeat:
echo str_repeat($variable, 10);