I want to repeat echo("text!") as often as $variable in php.
So let’s say
$variable=3
and I want the output to be:
"text! text! text!"
How do I get this as a loop? The following is what I tried to do but the loop isn’t stopping as it should.
$variable=readline(1,10)
for ($variable>0; $variable<11; $++){
echo("text!"); }
>Solution :
Either use loop or str_repeat:
$variable = 3;
for ($i = 1; $i <= $variable; $i++) {
echo 'text! ';
}
or
echo str_repeat('text! ', $variable);