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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.