From 5f9316e15e92dc345a382b93a542614ea2da9c45 Mon Sep 17 00:00:00 2001 From: ahwelp Date: Tue, 24 Jan 2023 13:32:08 +0000 Subject: [PATCH] Adding each method --- src/ORM/Collection.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ORM/Collection.php b/src/ORM/Collection.php index 987a996..fcb4a3c 100644 --- a/src/ORM/Collection.php +++ b/src/ORM/Collection.php @@ -79,7 +79,6 @@ class Collection implements \Countable, \IteratorAggregate, \ArrayAccess // Collection specific methods // - function get($forceCollection = false) { if (sizeof($this->items) == 1 && !$forceCollection) { @@ -130,4 +129,17 @@ class Collection implements \Countable, \IteratorAggregate, \ArrayAccess return $this->items[0]; } } + + /** + * Iterate over the colletion + * + * @param mixed $function + * @return void + */ + function each($function) + { + foreach($this->items as $item){ + $function($item); + } + } }