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 am Anuj Kumar, a professional web developer with 5+ years of experience in this sector. I found PHPGurukul in September 2015. My keen interest in technology and sharing knowledge with others became the main reason for starting PHPGurukul. My basic aim is to offer all web development tutorials like PHP, PDO, jQuery, PHP oops, MySQL, etc.
Apart from the tutorials, we also offer you PHP Projects, and we have around 100+ PHP Projects for you.
Recommended Tutorials for you
You may also like...