From 80e5da1dc6c76ce946c4022a6278a84041270eec Mon Sep 17 00:00:00 2001 From: Yoshi2889 Date: Thu, 29 Jun 2017 02:30:47 +0200 Subject: [PATCH] filter/without: Preserve keys Signed-off-by: Yoshi2889 --- src/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index d740210..281b0f6 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -43,7 +43,7 @@ public function __construct(\Closure $valueValidator, array $initialValues = []) public function filter(\Closure $condition): Collection { $collection = new self($this->validator); - foreach ($this->values() as $offset => $value) + foreach ((array) $this as $offset => $value) if ($condition($value)) $collection->offsetSet($offset, $value); @@ -58,7 +58,7 @@ public function filter(\Closure $condition): Collection public function without(\Closure $condition): Collection { $collection = new self($this->validator); - foreach ($this->values() as $offset => $value) + foreach ((array) $this as $offset => $value) if (!$condition($value)) $collection->offsetSet($offset, $value);