echo str_repeat('$',10);
The above command will print $ ten times.
$$$$$$$$$$
Syntax.
str_repeat (input $string, int $multiplier );
| Parameter | DESCRIPTION |
|---|---|
$string | Required : Input string which is to be repeated |
$multiplier | Required : Integer , Number of times the input string is to be repeated. |
for($i=1;$i<=10;$i++){
echo str_repeat("*",$i);
echo "<br>";
}
$separator = str_repeat('-=', 5);
echo $separator; // Output: -=-=-=-=-=-=
$divider = str_repeat('-', 50);
echo $divider; // Output: --------------------------------------------------
$str = 'Hello';
$padded_str = str_repeat(' ', 10) . $str;
echo $padded_str; // Output: " Hello"
$progress = 7; // Progress out of 10
$bar = str_repeat('=', $progress) . str_repeat('-', 10 - $progress);
echo "[$bar]"; // Output: [=======---]
$list_item = str_repeat('Item ', 5);
echo "$list_item
";
// Output: - Item
- Item
- Item
- Item
- Item
$password = str_repeat('ab1!', 3);
echo $password; // Output: ab1!ab1!ab1!
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.