5
21/10/2024 5:38 e m
Ämnesstart
Write a function that receives a string and a repeat count n. The function should return a new string:
Input:
- abc
- 3
Output:
abcabcabc
Input 2:
- String
- 2
Output 2:
StringString
1 Svar
4
21/10/2024 5:39 e m
My PHP function solution:
<?php
$string = readline();
$repeat = readline();
echo repeatString($string, $repeat);
function repeatString($s, $r) {
$newString = '';
for ($i = 0; $i < $r; $i++) {
$newString .= $s;
}
return $newString;
}
