0

We know the pre-defined function str_repeat();. Now how to make our own user defined function that works exact same as str_repeat. For eg str_repeat("John ",10); ( this will print John 10 times ). Help will be appreciated .

8/9/2016 2:36:36 PM

Sajen "The Empathy"

5 Answers

New Answer

+2

function repeat_word ($Word, $num) { $ret = ""; for ($i=0; $i <$num; $i++) { $ret .= $Word; } return $ret; } $a = repeat_word ("john",10); echo ($a); print : johnjohnjohn...

0

Thanks man What does .= means??

0

concatenation of string or number

0

use for loop. Take the parameters of your function as the string and the number of times you want to print it. Then use for loop to achieve it

0

.= is concatenation operator in php which is used to add(join) two strings eg.. johnjohn