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 .

9th Aug 2016, 2:36 PM
Sajen "The Empathy"
Sajen "The Empathy" - avatar
5 ответов
+ 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...
9th Aug 2016, 2:43 PM
francis
0
Thanks man What does .= means??
9th Aug 2016, 2:45 PM
Sajen "The Empathy"
Sajen "The Empathy" - avatar
0
concatenation of string or number
9th Aug 2016, 2:49 PM
francis
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
9th Aug 2016, 3:43 PM
Sumitabha Banerjee
Sumitabha Banerjee - avatar
0
.= is concatenation operator in php which is used to add(join) two strings eg.. johnjohn
25th Sep 2016, 3:57 AM
Sanjeev Pratap Singh
Sanjeev Pratap Singh - avatar