I want to repeat echo("text!")
as often as $variable
in PHP.
So, let’s say:
$variable = 3;
Now I want the output to be:
text! text! text!
How do I code this as a loop? I’ve tried the following but the loop isn’t stopping as it should:
$variable=readline(1,10)
for ($variable>0; $variable<11; $++){
echo("text!"); }
2
Answers
Either use loop or str_repeat:
or
One of the ways: use a function
(e.g. echotest($var1, $var2) which use a for loop to do the job)
You may simply change $variable (say change to 3000) and $string (say change to "Covid-19 ended !! " and see the changed result.
See this sandbox link :
http://www.createchhk.com/SOanswers/testso10oct2022b.php