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 web developer skilled in PHP, Laravel, CodeIgniter, MySQL, and Bootstrap. I love creating student-focused projects and sharing coding tips to help developers build real-world solutions with ease.
I specialize in building clean, responsive, and scalable web applications that solve real-world problems. I enjoy working on student-friendly project ideas, sharing coding tips, and helping beginners grow their development skills.
Through this website, I aim to simplify complex concepts, provide ready-to-use project solutions, and support the developer community with practical resources.
You may also like...