Last active
August 29, 2015 14:17
-
-
Save marianogappa/7f8cd009756cf681f8af to your computer and use it in GitHub Desktop.
PHP function equivalent to str_repeat but taking a callable instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function str_repeat_func($function, $multiplier) { | |
if(!is_callable($function) || !is_integer($multiplier) || $multiplier <= 0) | |
return ""; | |
$accumulator = ""; | |
for($i = 0; $i < $multiplier; $i++) | |
$accumulator .= call_user_func($function); | |
return $accumulator; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to pass in a method, you can't pass
$object->method
; instead you need to pass["className", "methodName"]
. This is PHP wtfness; sorry.