settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Repeat String - PHP Function Task

+1 vote

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

asked in PHP category by user hues

1 Answer

0 votes

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;
}
answered by user ak47seo
...