Skip to content

Instantly share code, notes, and snippets.

@marianogappa
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marianogappa/7f8cd009756cf681f8af to your computer and use it in GitHub Desktop.
Save marianogappa/7f8cd009756cf681f8af to your computer and use it in GitHub Desktop.
PHP function equivalent to str_repeat but taking a callable instead.
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;
}
@marianogappa
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment