Repeat is a repeater utility for PHP / Composer.
It makes it easy to repeat calling a function or similar operations.
Install the latest version with composer require jamsouf/repeat
require 'vendor/autoload.php';
$results = Repeat::_function(100, function () {
// your function code
});
$calculate = function ($result) {
// your function code
};
$results = Repeat::_function(20, $calculate);
$calculate = function ($result) {
// your function code
};
$until = function ($result) {
// return true or false
};
$results = Repeat::_function(50, $calculate, $until);
$result = Repeat::_string(10, 'v1.{j}.{i}', function ($result) {
return strpos($result, '.4.') !== false ? true : false;
}, ', ');
// => v1.1.0, v1.2.1, v1.3.2, v1.4.3
Repeat calling a function
- integer
$count
: How often the function should be called - callable
$func
: Function to call repeated - callable
$until
(optional): Repeat calling until this function returns true - => return array: Results from each function call
Repeat a string
- integer
$count
: How often the string should be repeated - string
$string
: String to repeat - callable
$until
(optional): Repeat the string until this function returns true - string
$delimiter
(optional): Signs to separate the strings - => return string: Repeated string