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
The variable $content will store the contents of both echo statements included above. What is the purpose of the variable variables in PHP? Ex: $$a= 'world'; Generally, double $ is used to append the variable value to a new variable to create that variable.
The PHP echo StatementThe echo statement can be used with or without parentheses: echo or echo() .
The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using the $ symbol before the $x value. These are called variable variables in PHP.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With