Search code examples
phpstringrepeat

Repeat a character N times


Is there any other way to print 40 dots in php?

I have this in my mind but I think this is wrong.. maybe there was a way like this.

<?php print(".",40);  ?>

Is it possible to do in that way? without the use of looping?


Solution

  • Yes ! use the str_repeat function:

    echo str_repeat('.', 40);