5
21/10/2024 5:38 pm
Topic starter
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 Answer
4
21/10/2024 5:39 pm
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; }