Allow for iterating over a collection with a callback.
This commit is contained in:
parent
5795e5c404
commit
c0125706e0
1 changed files with 9 additions and 0 deletions
|
|
@ -69,4 +69,13 @@ abstract class AbstractBase{{ class_name }}Collection
|
|||
|
||||
$this->contained[$offset] = $value;
|
||||
}
|
||||
|
||||
public function iterate($callback, ...$callbackArguments){
|
||||
foreach ($this->contained as $contained) {
|
||||
$iterationArguments = $callbackArguments;
|
||||
array_unshift($iterationArguments, $contained);
|
||||
call_user_func_array($callback, $iterationArguments);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue