How to repeat a string to a specific number of times in PHP?
by
Anuj Kumar
How to repeat a string to a specific number of times in PHP? The str_repeat() function is used to repeat a string, a specified number of times.
<?php
$string="PHP";
echo str_repeat($string, 3);
?>
OUTPUT
PHPPHPPHP
<?php
$string="PHP";
echo str_repeat($string, 2);
?>
OUTPUT
PHP
Tags: How to repeat a string to a specific number of times in PHP
Anuj Kumar
Hi, I’m Anuj Kumar, a passionate web developer with expertise in PHP, Laravel, CodeIgniter, MySQL, and Bootstrap. I enjoy building clean, responsive, and scalable web applications that address real-world challenges.
I love creating student-friendly projects, sharing practical coding tips, and helping developers—especially beginners—strengthen their skills. Through this website, my goal is to simplify complex concepts, offer ready-to-use project solutions, and support the developer community with useful, hands-on resources.
You may also like...