Last updated 2022-11-25 04:52:44

Repeat Words X Times |PHP

Repeating a given string several times is something you rarely have to do as a developer, however, sometimes you need to repeat white spaces to pad some text to keep spacing even across a list.


You can use either a loop or the built-in PHP str_repeat function to perform this action. The function takes in two parameters. First is the string you will like to repeat and the second is the number of times you will like to repeat this string.


01: 02: $output = str_repeat(' ', 2); 03: 04: echo $output //  

Here is another article you might like 😊 "Resize image to exact dimensions | Imagemagic"